Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduced LOC by replacing several instances of Value::Int {}, Value::Float{}, Value::Bool {}, and Value::String {} with Value::int(), Value::float(), Value::boolean() and Value::string() #7412

Merged
merged 4 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replace some Value::String{} with Value::string()
  • Loading branch information
webbedspace committed Dec 9, 2022
commit 95055b3d8ea3cd3663dc63a80ba99491573a08fb
5 changes: 1 addition & 4 deletions crates/nu-cli/src/completions/completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ impl NuCompleter {
Value::List {
vals: spans
.iter()
.map(|it| Value::String {
val: it.to_string(),
span: Span::unknown(),
})
.map(|it| Value::string(it, Span::unknown()))
.collect(),
span: Span::unknown(),
},
Expand Down
5 changes: 1 addition & 4 deletions crates/nu-cli/src/menus/menu_completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ impl Completer for NuMenuCompleter {

if let Some(buffer) = block.signature.get_positional(0) {
if let Some(buffer_id) = &buffer.var_id {
let line_buffer = Value::String {
val: parsed.remainder.to_string(),
span: self.span,
};
let line_buffer = Value::string(parsed.remainder, self.span);
self.stack.add_var(*buffer_id, line_buffer);
}
}
Expand Down
55 changes: 11 additions & 44 deletions crates/nu-cli/src/reedline_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,7 @@ mod test {
#[test]
fn test_send_event() {
let cols = vec!["send".to_string()];
let vals = vec![Value::String {
val: "Enter".to_string(),
span: Span::test_data(),
}];
let vals = vec![Value::string("Enter", Span::test_data())];

let span = Span::test_data();
let b = EventType::try_from_columns(&cols, &vals, &span).unwrap();
Expand All @@ -1016,10 +1013,7 @@ mod test {
#[test]
fn test_edit_event() {
let cols = vec!["edit".to_string()];
let vals = vec![Value::String {
val: "Clear".to_string(),
span: Span::test_data(),
}];
let vals = vec![Value::string("Clear", Span::test_data())];

let span = Span::test_data();
let b = EventType::try_from_columns(&cols, &vals, &span).unwrap();
Expand All @@ -1043,14 +1037,8 @@ mod test {
fn test_send_menu() {
let cols = vec!["send".to_string(), "name".to_string()];
let vals = vec![
Value::String {
val: "Menu".to_string(),
span: Span::test_data(),
},
Value::String {
val: "history_menu".to_string(),
span: Span::test_data(),
},
Value::string("Menu", Span::test_data()),
Value::string("history_menu", Span::test_data()),
];

let span = Span::test_data();
Expand All @@ -1076,14 +1064,8 @@ mod test {
// Menu event
let cols = vec!["send".to_string(), "name".to_string()];
let vals = vec![
Value::String {
val: "Menu".to_string(),
span: Span::test_data(),
},
Value::String {
val: "history_menu".to_string(),
span: Span::test_data(),
},
Value::string("Menu", Span::test_data()),
Value::string("history_menu", Span::test_data()),
];

let menu_event = Value::Record {
Expand All @@ -1094,10 +1076,7 @@ mod test {

// Enter event
let cols = vec!["send".to_string()];
let vals = vec![Value::String {
val: "Enter".to_string(),
span: Span::test_data(),
}];
let vals = vec![Value::string("Enter", Span::test_data())];

let enter_event = Value::Record {
cols,
Expand Down Expand Up @@ -1138,14 +1117,8 @@ mod test {
// Menu event
let cols = vec!["send".to_string(), "name".to_string()];
let vals = vec![
Value::String {
val: "Menu".to_string(),
span: Span::test_data(),
},
Value::String {
val: "history_menu".to_string(),
span: Span::test_data(),
},
Value::string("Menu", Span::test_data()),
Value::string("history_menu", Span::test_data()),
];

let menu_event = Value::Record {
Expand All @@ -1156,10 +1129,7 @@ mod test {

// Enter event
let cols = vec!["send".to_string()];
let vals = vec![Value::String {
val: "Enter".to_string(),
span: Span::test_data(),
}];
let vals = vec![Value::string("Enter", Span::test_data())];

let enter_event = Value::Record {
cols,
Expand Down Expand Up @@ -1187,10 +1157,7 @@ mod test {
#[test]
fn test_error() {
let cols = vec!["not_exist".to_string()];
let vals = vec![Value::String {
val: "Enter".to_string(),
span: Span::test_data(),
}];
let vals = vec![Value::string("Enter", Span::test_data())];

let span = Span::test_data();
let b = EventType::try_from_columns(&cols, &vals, &span);
Expand Down
5 changes: 1 addition & 4 deletions crates/nu-cli/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ pub fn evaluate_repl(
// seed env vars
stack.add_env_var(
"CMD_DURATION_MS".into(),
Value::String {
val: "0823".to_string(),
span: Span::unknown(),
},
Value::string("0823", Span::unknown()),
);

stack.add_env_var("LAST_EXIT_CODE".into(), Value::int(0, Span::unknown()));
Expand Down
40 changes: 8 additions & 32 deletions crates/nu-command/src/conversions/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,14 @@ impl Command for Fmt {
"upperhex".into(),
],
vals: vec![
Value::String {
val: "0b101010".to_string(),
span: Span::test_data(),
},
Value::String {
val: "42".to_string(),
span: Span::test_data(),
},
Value::String {
val: "42".to_string(),
span: Span::test_data(),
},
Value::String {
val: "4.2e1".to_string(),
span: Span::test_data(),
},
Value::String {
val: "0x2a".to_string(),
span: Span::test_data(),
},
Value::String {
val: "0o52".to_string(),
span: Span::test_data(),
},
Value::String {
val: "4.2E1".to_string(),
span: Span::test_data(),
},
Value::String {
val: "0x2A".to_string(),
span: Span::test_data(),
},
Value::string("0b101010", Span::test_data()),
Value::string("42", Span::test_data()),
Value::string("42", Span::test_data()),
Value::string("4.2e1", Span::test_data()),
Value::string("0x2a", Span::test_data()),
Value::string("0o52", Span::test_data()),
Value::string("4.2E1", Span::test_data()),
Value::string("0x2A", Span::test_data()),
],
span: Span::test_data(),
}),
Expand Down
35 changes: 7 additions & 28 deletions crates/nu-command/src/conversions/into/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,34 +79,22 @@ impl Command for SubCommand {
Example {
description: "convert integer to string and append three decimal places",
example: "5 | into string -d 3",
result: Some(Value::String {
val: "5.000".to_string(),
span: Span::test_data(),
}),
result: Some(Value::string("5.000", Span::test_data())),
},
Example {
description: "convert decimal to string and round to nearest integer",
example: "1.7 | into string -d 0",
result: Some(Value::String {
val: "2".to_string(),
span: Span::test_data(),
}),
result: Some(Value::string("2", Span::test_data())),
},
Example {
description: "convert decimal to string",
example: "1.7 | into string -d 1",
result: Some(Value::String {
val: "1.7".to_string(),
span: Span::test_data(),
}),
result: Some(Value::string("1.7", Span::test_data())),
},
Example {
description: "convert decimal to string and limit to 2 decimals",
example: "1.734 | into string -d 2",
result: Some(Value::String {
val: "1.73".to_string(),
span: Span::test_data(),
}),
result: Some(Value::string("1.73", Span::test_data())),
},
Example {
description: "try to convert decimal to string and provide negative decimal points",
Expand All @@ -123,26 +111,17 @@ impl Command for SubCommand {
Example {
description: "convert decimal to string",
example: "4.3 | into string",
result: Some(Value::String {
val: "4.3".to_string(),
span: Span::test_data(),
}),
result: Some(Value::string("4.3", Span::test_data())),
},
Example {
description: "convert string to string",
example: "'1234' | into string",
result: Some(Value::String {
val: "1234".to_string(),
span: Span::test_data(),
}),
result: Some(Value::string("1234", Span::test_data())),
},
Example {
description: "convert boolean to string",
example: "true | into string",
result: Some(Value::String {
val: "true".to_string(),
span: Span::test_data(),
}),
result: Some(Value::string("true", Span::test_data())),
},
// TODO: This should work but does not; see https://github.com/nushell/nushell/issues/7032
// Example {
Expand Down
5 changes: 1 addition & 4 deletions crates/nu-command/src/core_commands/def_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ def-env cd_with_fallback [arg = ""] {
vec![Example {
description: "Set environment variable by call a custom command",
example: r#"def-env foo [] { let-env BAR = "BAZ" }; foo; $env.BAR"#,
result: Some(Value::String {
val: "BAZ".to_string(),
span: Span::test_data(),
}),
result: Some(Value::string("BAZ", Span::test_data())),
}]
}
}
8 changes: 1 addition & 7 deletions crates/nu-command/src/core_commands/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ little reason to use this over just writing the values as-is."#
std::cmp::Ordering::Equal => PipelineData::Value(to_be_echoed[0].clone(), None),

// When there are no elements, we echo the empty string
std::cmp::Ordering::Less => PipelineData::Value(
Value::String {
val: "".to_string(),
span: call.head,
},
None,
),
std::cmp::Ordering::Less => PipelineData::Value(Value::string("", call.head), None),
}
})
}
Expand Down
5 changes: 1 addition & 4 deletions crates/nu-command/src/core_commands/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ impl Command for ExportCommand {
vec![Example {
description: "Export a definition from a module",
example: r#"module utils { export def my-command [] { "hello" } }; use utils my-command; my-command"#,
result: Some(Value::String {
val: "hello".to_string(),
span: Span::test_data(),
}),
result: Some(Value::string("hello", Span::test_data())),
}]
}

Expand Down
5 changes: 1 addition & 4 deletions crates/nu-command/src/core_commands/export_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ impl Command for ExportDef {
vec![Example {
description: "Define a custom command in a module and call it",
example: r#"module spam { export def foo [] { "foo" } }; use spam foo; foo"#,
result: Some(Value::String {
val: "foo".to_string(),
span: Span::test_data(),
}),
result: Some(Value::string("foo", Span::test_data())),
}]
}

Expand Down
5 changes: 1 addition & 4 deletions crates/nu-command/src/core_commands/export_def_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ export def-env cd_with_fallback [arg = ""] {
vec![Example {
description: "Define a custom command that participates in the environment in a module and call it",
example: r#"module foo { export def-env bar [] { let-env FOO_BAR = "BAZ" } }; use foo bar; bar; $env.FOO_BAR"#,
result: Some(Value::String {
val: "BAZ".to_string(),
span: Span::test_data(),
}),
result: Some(Value::string("BAZ", Span::test_data())),
}]
}

Expand Down
5 changes: 1 addition & 4 deletions crates/nu-command/src/core_commands/export_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ impl Command for ExportUse {
use eggs foo
foo
"#,
result: Some(Value::String {
val: "foo".to_string(),
span: Span::test_data(),
}),
result: Some(Value::string("foo", Span::test_data())),
}]
}

Expand Down
16 changes: 3 additions & 13 deletions crates/nu-command/src/core_commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ fn help(
});

cols.push("category".into());
vals.push(Value::String {
val: sig.category.to_string(),
span: head,
});
vals.push(Value::string(sig.category.to_string(), head));

cols.push("command_type".into());
vals.push(Value::String {
Expand Down Expand Up @@ -231,10 +228,7 @@ fn help(
});

cols.push("category".into());
vals.push(Value::String {
val: sig.category.to_string(),
span: head,
});
vals.push(Value::string(sig.category.to_string(), head));

cols.push("command_type".into());
vals.push(Value::String {
Expand Down Expand Up @@ -334,11 +328,7 @@ Get the processes on your system actively using CPU:

You can also learn more at https://www.nushell.sh/book/"#;

Ok(Value::String {
val: msg.into(),
span: head,
}
.into_pipeline_data())
Ok(Value::string(msg, head).into_pipeline_data())
}
}

Expand Down
Loading