mirror of
https://github.com/nushell/nushell.git
synced 2025-08-16 00:58:14 +02:00
Invert &Option
s to Option<&T>
(#10315)
Elide the reference for `Copy` type (`usize`) Use the canonical deref where possible. * `&Box` -> `&` * `&String` -> `&str` * `&PathBuf` -> `&Path` Skips the ctrl-C handler for now.
This commit is contained in:
committed by
GitHub
parent
3e14dc3eb8
commit
a14e9e0a2e
@ -61,15 +61,15 @@ impl Command for ToNuon {
|
||||
let value = input.into_value(span);
|
||||
|
||||
let nuon_result = if raw {
|
||||
value_to_string(&value, span, 0, &None)
|
||||
value_to_string(&value, span, 0, None)
|
||||
} else if use_tabs {
|
||||
let tab_count: usize = call.get_flag(engine_state, stack, "tabs")?.unwrap_or(1);
|
||||
value_to_string(&value, span, 0, &Some("\t".repeat(tab_count)))
|
||||
value_to_string(&value, span, 0, Some(&"\t".repeat(tab_count)))
|
||||
} else if use_indent {
|
||||
let indent: usize = call.get_flag(engine_state, stack, "indent")?.unwrap_or(2);
|
||||
value_to_string(&value, span, 0, &Some(" ".repeat(indent)))
|
||||
value_to_string(&value, span, 0, Some(&" ".repeat(indent)))
|
||||
} else {
|
||||
value_to_string(&value, span, 0, &None)
|
||||
value_to_string(&value, span, 0, None)
|
||||
};
|
||||
|
||||
match nuon_result {
|
||||
@ -119,7 +119,7 @@ pub fn value_to_string(
|
||||
v: &Value,
|
||||
span: Span,
|
||||
depth: usize,
|
||||
indent: &Option<String>,
|
||||
indent: Option<&str>,
|
||||
) -> Result<String, ShellError> {
|
||||
let (nl, sep) = get_true_separators(indent);
|
||||
let idt = get_true_indentation(depth, indent);
|
||||
@ -290,14 +290,14 @@ pub fn value_to_string(
|
||||
}
|
||||
}
|
||||
|
||||
fn get_true_indentation(depth: usize, indent: &Option<String>) -> String {
|
||||
fn get_true_indentation(depth: usize, indent: Option<&str>) -> String {
|
||||
match indent {
|
||||
Some(i) => i.repeat(depth),
|
||||
None => "".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_true_separators(indent: &Option<String>) -> (String, String) {
|
||||
fn get_true_separators(indent: Option<&str>) -> (String, String) {
|
||||
match indent {
|
||||
Some(_) => ("\n".to_string(), "".to_string()),
|
||||
None => ("".to_string(), " ".to_string()),
|
||||
@ -308,7 +308,7 @@ fn value_to_string_without_quotes(
|
||||
v: &Value,
|
||||
span: Span,
|
||||
depth: usize,
|
||||
indent: &Option<String>,
|
||||
indent: Option<&str>,
|
||||
) -> Result<String, ShellError> {
|
||||
match v {
|
||||
Value::String { val, .. } => Ok({
|
||||
|
Reference in New Issue
Block a user