mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +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
@ -44,7 +44,7 @@ enum InputNumType {
|
||||
SignedEight,
|
||||
}
|
||||
|
||||
fn get_number_bytes(number_bytes: &Option<Spanned<String>>) -> NumberBytes {
|
||||
fn get_number_bytes(number_bytes: Option<&Spanned<String>>) -> NumberBytes {
|
||||
match number_bytes.as_ref() {
|
||||
None => NumberBytes::Eight,
|
||||
Some(size) => match size.item.as_str() {
|
||||
|
@ -57,7 +57,7 @@ impl Command for BitsNot {
|
||||
let signed = call.has_flag("signed");
|
||||
let number_bytes: Option<Spanned<String>> =
|
||||
call.get_flag(engine_state, stack, "number-bytes")?;
|
||||
let bytes_len = get_number_bytes(&number_bytes);
|
||||
let bytes_len = get_number_bytes(number_bytes.as_ref());
|
||||
if let NumberBytes::Invalid = bytes_len {
|
||||
if let Some(val) = number_bytes {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
|
@ -60,7 +60,7 @@ impl Command for BitsRol {
|
||||
let signed = call.has_flag("signed");
|
||||
let number_bytes: Option<Spanned<String>> =
|
||||
call.get_flag(engine_state, stack, "number-bytes")?;
|
||||
let bytes_len = get_number_bytes(&number_bytes);
|
||||
let bytes_len = get_number_bytes(number_bytes.as_ref());
|
||||
if let NumberBytes::Invalid = bytes_len {
|
||||
if let Some(val) = number_bytes {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
|
@ -60,7 +60,7 @@ impl Command for BitsRor {
|
||||
let signed = call.has_flag("signed");
|
||||
let number_bytes: Option<Spanned<String>> =
|
||||
call.get_flag(engine_state, stack, "number-bytes")?;
|
||||
let bytes_len = get_number_bytes(&number_bytes);
|
||||
let bytes_len = get_number_bytes(number_bytes.as_ref());
|
||||
if let NumberBytes::Invalid = bytes_len {
|
||||
if let Some(val) = number_bytes {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
|
@ -60,7 +60,7 @@ impl Command for BitsShl {
|
||||
let signed = call.has_flag("signed");
|
||||
let number_bytes: Option<Spanned<String>> =
|
||||
call.get_flag(engine_state, stack, "number-bytes")?;
|
||||
let bytes_len = get_number_bytes(&number_bytes);
|
||||
let bytes_len = get_number_bytes(number_bytes.as_ref());
|
||||
if let NumberBytes::Invalid = bytes_len {
|
||||
if let Some(val) = number_bytes {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
|
@ -60,7 +60,7 @@ impl Command for BitsShr {
|
||||
let signed = call.has_flag("signed");
|
||||
let number_bytes: Option<Spanned<String>> =
|
||||
call.get_flag(engine_state, stack, "number-bytes")?;
|
||||
let bytes_len = get_number_bytes(&number_bytes);
|
||||
let bytes_len = get_number_bytes(number_bytes.as_ref());
|
||||
if let NumberBytes::Invalid = bytes_len {
|
||||
if let Some(val) = number_bytes {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
|
@ -48,7 +48,7 @@ enum HorizontalDirection {
|
||||
|
||||
fn horizontal_rotate_value(
|
||||
value: Value,
|
||||
by: &Option<usize>,
|
||||
by: Option<usize>,
|
||||
cells_only: bool,
|
||||
direction: &HorizontalDirection,
|
||||
) -> Result<Value, ShellError> {
|
||||
|
@ -106,7 +106,7 @@ impl Command for RollLeft {
|
||||
let cells_only = call.has_flag("cells-only");
|
||||
let value = input.into_value(call.head);
|
||||
let rotated_value =
|
||||
horizontal_rotate_value(value, &by, cells_only, &HorizontalDirection::Left)?;
|
||||
horizontal_rotate_value(value, by, cells_only, &HorizontalDirection::Left)?;
|
||||
|
||||
Ok(rotated_value.into_pipeline_data().set_metadata(metadata))
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ impl Command for RollRight {
|
||||
let cells_only = call.has_flag("cells-only");
|
||||
let value = input.into_value(call.head);
|
||||
let rotated_value =
|
||||
horizontal_rotate_value(value, &by, cells_only, &HorizontalDirection::Right)?;
|
||||
horizontal_rotate_value(value, by, cells_only, &HorizontalDirection::Right)?;
|
||||
|
||||
Ok(rotated_value.into_pipeline_data().set_metadata(metadata))
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ impl Command for ToHtml {
|
||||
|
||||
fn get_theme_from_asset_file(
|
||||
is_dark: bool,
|
||||
theme: &Option<Spanned<String>>,
|
||||
theme: Option<&Spanned<String>>,
|
||||
) -> Result<HashMap<&'static str, String>, ShellError> {
|
||||
let theme_name = match theme {
|
||||
Some(s) => &s.item,
|
||||
@ -301,7 +301,7 @@ fn to_html(
|
||||
None => head,
|
||||
};
|
||||
|
||||
let color_hm = get_theme_from_asset_file(dark, &theme);
|
||||
let color_hm = get_theme_from_asset_file(dark, theme.as_ref());
|
||||
let color_hm = match color_hm {
|
||||
Ok(c) => c,
|
||||
_ => {
|
||||
|
@ -98,12 +98,12 @@ fn operate(
|
||||
|
||||
if column_paths.is_empty() {
|
||||
input.map(
|
||||
move |v| process_value(&v, &text),
|
||||
move |v| process_value(&v, text.as_deref()),
|
||||
engine_state.ctrlc.clone(),
|
||||
)
|
||||
} else {
|
||||
input.map(
|
||||
move |v| process_each_path(v, &column_paths, &text, command_span),
|
||||
move |v| process_each_path(v, &column_paths, text.as_deref(), command_span),
|
||||
engine_state.ctrlc.clone(),
|
||||
)
|
||||
}
|
||||
@ -112,7 +112,7 @@ fn operate(
|
||||
fn process_each_path(
|
||||
mut value: Value,
|
||||
column_paths: &[CellPath],
|
||||
text: &Option<String>,
|
||||
text: Option<&str>,
|
||||
command_span: Span,
|
||||
) -> Value {
|
||||
for path in column_paths {
|
||||
@ -124,11 +124,11 @@ fn process_each_path(
|
||||
value
|
||||
}
|
||||
|
||||
fn process_value(value: &Value, text: &Option<String>) -> Value {
|
||||
fn process_value(value: &Value, text: Option<&str>) -> Value {
|
||||
let span = value.span();
|
||||
match value {
|
||||
Value::String { val, .. } => {
|
||||
let text = text.as_deref().unwrap_or(val.as_str());
|
||||
let text = text.unwrap_or(val.as_str());
|
||||
let result = add_osc_link(text, val.as_str());
|
||||
Value::string(result, span)
|
||||
}
|
||||
|
Reference in New Issue
Block a user