Rust 1.85, edition=2024 (#15741)

This commit is contained in:
Jack Wright
2025-05-13 07:49:30 -07:00
committed by GitHub
parent 1a0986903f
commit c2ac8f730e
793 changed files with 4276 additions and 3687 deletions

View File

@ -16,8 +16,8 @@ mod test_examples {
};
use nu_protocol::{
engine::{Command, EngineState, StateWorkingSet},
Type,
engine::{Command, EngineState, StateWorkingSet},
};
use std::collections::HashSet;

View File

@ -65,7 +65,7 @@ impl Command for BitsAnd {
return Err(ShellError::TypeMismatch {
err_message: "Endian must be one of native, little, big".to_string(),
span: endian.span,
})
});
}
}
} else {
@ -113,8 +113,7 @@ impl Command for BitsAnd {
])),
},
Example {
description:
"Apply bitwise and to binary data of varying lengths with specified endianness",
description: "Apply bitwise and to binary data of varying lengths with specified endianness",
example: "0x[c0 ff ee] | bits and 0x[ff] --endian big",
result: Some(Value::test_binary(vec![0x00, 0x00, 0xee])),
},

View File

@ -1,5 +1,5 @@
use super::{get_number_bytes, NumberBytes};
use nu_cmd_base::input_handler::{operate, CmdArgument};
use super::{NumberBytes, get_number_bytes};
use nu_cmd_base::input_handler::{CmdArgument, operate};
use nu_engine::command_prelude::*;
#[derive(Clone)]
@ -100,8 +100,7 @@ impl Command for BitsNot {
)),
},
Example {
description:
"Apply logical negation to a list of numbers, treat input as 2 bytes number",
description: "Apply logical negation to a list of numbers, treat input as 2 bytes number",
example: "[4 3 2] | bits not --number-bytes 2",
result: Some(Value::list(
vec![
@ -113,8 +112,7 @@ impl Command for BitsNot {
)),
},
Example {
description:
"Apply logical negation to a list of numbers, treat input as signed number",
description: "Apply logical negation to a list of numbers, treat input as signed number",
example: "[4 3 2] | bits not --signed",
result: Some(Value::list(
vec![

View File

@ -66,7 +66,7 @@ impl Command for BitsOr {
return Err(ShellError::TypeMismatch {
err_message: "Endian must be one of native, little, big".to_string(),
span: endian.span,
})
});
}
}
} else {
@ -106,8 +106,7 @@ impl Command for BitsOr {
result: Some(Value::test_binary(vec![0xca, 0xfe])),
},
Example {
description:
"Apply bitwise or to binary data of varying lengths with specified endianness",
description: "Apply bitwise or to binary data of varying lengths with specified endianness",
example: "0x[c0 ff ee] | bits or 0x[ff] --endian big",
result: Some(Value::test_binary(vec![0xc0, 0xff, 0xff])),
},

View File

@ -1,5 +1,5 @@
use super::{get_input_num_type, get_number_bytes, InputNumType, NumberBytes};
use nu_cmd_base::input_handler::{operate, CmdArgument};
use super::{InputNumType, NumberBytes, get_input_num_type, get_number_bytes};
use nu_cmd_base::input_handler::{CmdArgument, operate};
use nu_engine::command_prelude::*;
struct Arguments {
@ -222,7 +222,8 @@ fn rotate_bytes_and_bits_left(data: &[u8], byte_shift: usize, bit_shift: usize)
debug_assert!(byte_shift < data.len());
debug_assert!(
(1..8).contains(&bit_shift),
"Bit shifts of 0 can't be handled by this impl and everything else should be part of the byteshift");
"Bit shifts of 0 can't be handled by this impl and everything else should be part of the byteshift"
);
let mut bytes = Vec::with_capacity(data.len());
let mut next_index = byte_shift;
for _ in 0..data.len() {

View File

@ -1,5 +1,5 @@
use super::{get_input_num_type, get_number_bytes, InputNumType, NumberBytes};
use nu_cmd_base::input_handler::{operate, CmdArgument};
use super::{InputNumType, NumberBytes, get_input_num_type, get_number_bytes};
use nu_cmd_base::input_handler::{CmdArgument, operate};
use nu_engine::command_prelude::*;
struct Arguments {

View File

@ -1,6 +1,6 @@
use super::{get_input_num_type, get_number_bytes, InputNumType, NumberBytes};
use super::{InputNumType, NumberBytes, get_input_num_type, get_number_bytes};
use itertools::Itertools;
use nu_cmd_base::input_handler::{operate, CmdArgument};
use nu_cmd_base::input_handler::{CmdArgument, operate};
use nu_engine::command_prelude::*;
use std::iter;
@ -237,7 +237,8 @@ fn shift_bytes_left(data: &[u8], byte_shift: usize) -> Vec<u8> {
fn shift_bytes_and_bits_left(data: &[u8], byte_shift: usize, bit_shift: usize) -> Vec<u8> {
use itertools::Position::*;
debug_assert!((1..8).contains(&bit_shift),
debug_assert!(
(1..8).contains(&bit_shift),
"Bit shifts of 0 can't be handled by this impl and everything else should be part of the byteshift"
);
data.iter()

View File

@ -1,5 +1,5 @@
use super::{get_input_num_type, get_number_bytes, InputNumType, NumberBytes};
use nu_cmd_base::input_handler::{operate, CmdArgument};
use super::{InputNumType, NumberBytes, get_input_num_type, get_number_bytes};
use nu_cmd_base::input_handler::{CmdArgument, operate};
use nu_engine::command_prelude::*;
struct Arguments {

View File

@ -66,7 +66,7 @@ impl Command for BitsXor {
return Err(ShellError::TypeMismatch {
err_message: "Endian must be one of native, little, big".to_string(),
span: endian.span,
})
});
}
}
} else {
@ -106,8 +106,7 @@ impl Command for BitsXor {
result: Some(Value::test_binary(vec![0x70, 0x40])),
},
Example {
description:
"Apply bitwise xor to binary data of varying lengths with specified endianness",
description: "Apply bitwise xor to binary data of varying lengths with specified endianness",
example: "0x[ca fe] | bits xor 0x[aa] --endian big",
result: Some(Value::test_binary(vec![0xca, 0x54])),
},

View File

@ -1,4 +1,4 @@
use nu_engine::{command_prelude::*, ClosureEval, ClosureEvalOnce};
use nu_engine::{ClosureEval, ClosureEvalOnce, command_prelude::*};
use nu_protocol::engine::Closure;
#[derive(Clone)]

View File

@ -1,4 +1,4 @@
use super::{vertical_rotate_value, VerticalDirection};
use super::{VerticalDirection, vertical_rotate_value};
use nu_engine::command_prelude::*;
#[derive(Clone)]

View File

@ -1,4 +1,4 @@
use super::{horizontal_rotate_value, HorizontalDirection};
use super::{HorizontalDirection, horizontal_rotate_value};
use nu_engine::command_prelude::*;
#[derive(Clone)]

View File

@ -1,4 +1,4 @@
use super::{horizontal_rotate_value, HorizontalDirection};
use super::{HorizontalDirection, horizontal_rotate_value};
use nu_engine::command_prelude::*;
#[derive(Clone)]

View File

@ -1,4 +1,4 @@
use super::{vertical_rotate_value, VerticalDirection};
use super::{VerticalDirection, vertical_rotate_value};
use nu_engine::command_prelude::*;
#[derive(Clone)]

View File

@ -36,104 +36,93 @@ impl Command for Rotate {
description: "Rotate a record clockwise, producing a table (like `transpose` but with column order reversed)",
example: "{a:1, b:2} | rotate",
result: Some(Value::test_list(vec![
Value::test_record(record! {
"column0" => Value::test_int(1),
"column1" => Value::test_string("a"),
}),
Value::test_record(record! {
"column0" => Value::test_int(2),
"column1" => Value::test_string("b"),
}),
],
)),
Value::test_record(record! {
"column0" => Value::test_int(1),
"column1" => Value::test_string("a"),
}),
Value::test_record(record! {
"column0" => Value::test_int(2),
"column1" => Value::test_string("b"),
}),
])),
},
Example {
description: "Rotate 2x3 table clockwise",
example: "[[a b]; [1 2] [3 4] [5 6]] | rotate",
result: Some(Value::test_list(
vec![
Value::test_record(record! {
"column0" => Value::test_int(5),
"column1" => Value::test_int(3),
"column2" => Value::test_int(1),
"column3" => Value::test_string("a"),
}),
Value::test_record(record! {
"column0" => Value::test_int(6),
"column1" => Value::test_int(4),
"column2" => Value::test_int(2),
"column3" => Value::test_string("b"),
}),
],
)),
result: Some(Value::test_list(vec![
Value::test_record(record! {
"column0" => Value::test_int(5),
"column1" => Value::test_int(3),
"column2" => Value::test_int(1),
"column3" => Value::test_string("a"),
}),
Value::test_record(record! {
"column0" => Value::test_int(6),
"column1" => Value::test_int(4),
"column2" => Value::test_int(2),
"column3" => Value::test_string("b"),
}),
])),
},
Example {
description: "Rotate table clockwise and change columns names",
example: "[[a b]; [1 2]] | rotate col_a col_b",
result: Some(Value::test_list(
vec![
Value::test_record(record! {
"col_a" => Value::test_int(1),
"col_b" => Value::test_string("a"),
}),
Value::test_record(record! {
"col_a" => Value::test_int(2),
"col_b" => Value::test_string("b"),
}),
],
)),
result: Some(Value::test_list(vec![
Value::test_record(record! {
"col_a" => Value::test_int(1),
"col_b" => Value::test_string("a"),
}),
Value::test_record(record! {
"col_a" => Value::test_int(2),
"col_b" => Value::test_string("b"),
}),
])),
},
Example {
description: "Rotate table counter clockwise",
example: "[[a b]; [1 2]] | rotate --ccw",
result: Some(Value::test_list(
vec![
Value::test_record(record! {
"column0" => Value::test_string("b"),
"column1" => Value::test_int(2),
}),
Value::test_record(record! {
"column0" => Value::test_string("a"),
"column1" => Value::test_int(1),
}),
],
)),
result: Some(Value::test_list(vec![
Value::test_record(record! {
"column0" => Value::test_string("b"),
"column1" => Value::test_int(2),
}),
Value::test_record(record! {
"column0" => Value::test_string("a"),
"column1" => Value::test_int(1),
}),
])),
},
Example {
description: "Rotate table counter-clockwise",
example: "[[a b]; [1 2] [3 4] [5 6]] | rotate --ccw",
result: Some(Value::test_list(
vec![
Value::test_record(record! {
"column0" => Value::test_string("b"),
"column1" => Value::test_int(2),
"column2" => Value::test_int(4),
"column3" => Value::test_int(6),
}),
Value::test_record(record! {
"column0" => Value::test_string("a"),
"column1" => Value::test_int(1),
"column2" => Value::test_int(3),
"column3" => Value::test_int(5),
}),
],
)),
result: Some(Value::test_list(vec![
Value::test_record(record! {
"column0" => Value::test_string("b"),
"column1" => Value::test_int(2),
"column2" => Value::test_int(4),
"column3" => Value::test_int(6),
}),
Value::test_record(record! {
"column0" => Value::test_string("a"),
"column1" => Value::test_int(1),
"column2" => Value::test_int(3),
"column3" => Value::test_int(5),
}),
])),
},
Example {
description: "Rotate table counter-clockwise and change columns names",
example: "[[a b]; [1 2]] | rotate --ccw col_a col_b",
result: Some(Value::test_list(
vec![
Value::test_record(record! {
"col_a" => Value::test_string("b"),
"col_b" => Value::test_int(2),
}),
Value::test_record(record! {
"col_a" => Value::test_string("a"),
"col_b" => Value::test_int(1),
}),
],
)),
result: Some(Value::test_list(vec![
Value::test_record(record! {
"col_a" => Value::test_string("b"),
"col_b" => Value::test_int(2),
}),
Value::test_record(record! {
"col_a" => Value::test_string("a"),
"col_b" => Value::test_int(1),
}),
])),
},
]
}

View File

@ -1,5 +1,5 @@
use nu_engine::{command_prelude::*, ClosureEval};
use nu_protocol::{engine::Closure, PipelineIterator};
use nu_engine::{ClosureEval, command_prelude::*};
use nu_protocol::{PipelineIterator, engine::Closure};
use std::collections::HashSet;
#[derive(Clone)]

View File

@ -267,7 +267,7 @@ fn to_html(
span: Some(theme_span),
help: None,
inner: vec![],
})
});
}
};

View File

@ -1,4 +1,4 @@
use nu_ansi_term::{build_all_gradient_text, gradient::TargetGround, Gradient, Rgb};
use nu_ansi_term::{Gradient, Rgb, build_all_gradient_text, gradient::TargetGround};
use nu_engine::command_prelude::*;
#[derive(Clone)]
@ -70,29 +70,25 @@ impl Command for SubCommand {
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "draw text in a gradient with foreground start and end colors",
example:
"'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff' --fgend '0xe81cff'",
result: None,
},
Example {
description: "draw text in a gradient with foreground start and end colors and background start and end colors",
example:
"'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff' --fgend '0xe81cff' --bgstart '0xe81cff' --bgend '0x40c9ff'",
result: None,
},
Example {
description: "draw text in a gradient by specifying foreground start color - end color is assumed to be black",
example:
"'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff'",
result: None,
},
Example {
description: "draw text in a gradient by specifying foreground end color - start color is assumed to be black",
example:
"'Hello, Nushell! This is a gradient.' | ansi gradient --fgend '0xe81cff'",
result: None,
},
description: "draw text in a gradient with foreground start and end colors",
example: "'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff' --fgend '0xe81cff'",
result: None,
},
Example {
description: "draw text in a gradient with foreground start and end colors and background start and end colors",
example: "'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff' --fgend '0xe81cff' --bgstart '0xe81cff' --bgend '0x40c9ff'",
result: None,
},
Example {
description: "draw text in a gradient by specifying foreground start color - end color is assumed to be black",
example: "'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff'",
result: None,
},
Example {
description: "draw text in a gradient by specifying foreground end color - start color is assumed to be black",
example: "'Hello, Nushell! This is a gradient.' | ansi gradient --fgend '0xe81cff'",
result: None,
},
]
}
}
@ -300,7 +296,7 @@ fn action(
#[cfg(test)]
mod tests {
use super::{action, SubCommand};
use super::{SubCommand, action};
use nu_ansi_term::Rgb;
use nu_protocol::{Span, Value};
@ -314,7 +310,9 @@ mod tests {
#[test]
fn test_fg_gradient() {
let input_string = Value::test_string("Hello, World!");
let expected = Value::test_string("\u{1b}[38;2;64;201;255mH\u{1b}[38;2;76;187;254me\u{1b}[38;2;89;174;254ml\u{1b}[38;2;102;160;254ml\u{1b}[38;2;115;147;254mo\u{1b}[38;2;128;133;254m,\u{1b}[38;2;141;120;254m \u{1b}[38;2;153;107;254mW\u{1b}[38;2;166;94;254mo\u{1b}[38;2;179;80;254mr\u{1b}[38;2;192;67;254ml\u{1b}[38;2;205;53;254md\u{1b}[38;2;218;40;254m!\u{1b}[0m");
let expected = Value::test_string(
"\u{1b}[38;2;64;201;255mH\u{1b}[38;2;76;187;254me\u{1b}[38;2;89;174;254ml\u{1b}[38;2;102;160;254ml\u{1b}[38;2;115;147;254mo\u{1b}[38;2;128;133;254m,\u{1b}[38;2;141;120;254m \u{1b}[38;2;153;107;254mW\u{1b}[38;2;166;94;254mo\u{1b}[38;2;179;80;254mr\u{1b}[38;2;192;67;254ml\u{1b}[38;2;205;53;254md\u{1b}[38;2;218;40;254m!\u{1b}[0m",
);
let fg_start = Rgb::from_hex_string("0x40c9ff".to_string());
let fg_end = Rgb::from_hex_string("0xe81cff".to_string());
let actual = action(

View File

@ -1,9 +1,9 @@
use std::io::{self, Read, Write};
use nu_cmd_base::input_handler::{operate, CmdArgument};
use nu_cmd_base::input_handler::{CmdArgument, operate};
use nu_engine::command_prelude::*;
use nu_protocol::{shell_error::io::IoError, Signals};
use nu_protocol::{Signals, shell_error::io::IoError};
use num_traits::ToPrimitive;
struct Arguments {
@ -68,42 +68,33 @@ impl Command for FormatBits {
Example {
description: "convert a binary value into a string, padded to 8 places with 0s",
example: "0x[1] | format bits",
result: Some(Value::string("00000001",
Span::test_data(),
)),
result: Some(Value::string("00000001", Span::test_data())),
},
Example {
description: "convert an int into a string, padded to 8 places with 0s",
example: "1 | format bits",
result: Some(Value::string("00000001",
Span::test_data(),
)),
result: Some(Value::string("00000001", Span::test_data())),
},
Example {
description: "convert a filesize value into a string, padded to 8 places with 0s",
example: "1b | format bits",
result: Some(Value::string("00000001",
Span::test_data(),
)),
result: Some(Value::string("00000001", Span::test_data())),
},
Example {
description: "convert a duration value into a string, padded to 8 places with 0s",
example: "1ns | format bits",
result: Some(Value::string("00000001",
Span::test_data(),
)),
result: Some(Value::string("00000001", Span::test_data())),
},
Example {
description: "convert a boolean value into a string, padded to 8 places with 0s",
example: "true | format bits",
result: Some(Value::string("00000001",
Span::test_data(),
)),
result: Some(Value::string("00000001", Span::test_data())),
},
Example {
description: "convert a string into a raw binary string, padded with 0s to 8 places",
example: "'nushell.sh' | format bits",
result: Some(Value::string("01101110 01110101 01110011 01101000 01100101 01101100 01101100 00101110 01110011 01101000",
result: Some(Value::string(
"01101110 01110101 01110011 01101000 01100101 01101100 01101100 00101110 01110011 01101000",
Span::test_data(),
)),
},

View File

@ -1,5 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::{ast::PathMember, engine::StateWorkingSet, Config, ListStream};
use nu_protocol::{Config, ListStream, ast::PathMember, engine::StateWorkingSet};
#[derive(Clone)]
pub struct FormatPattern;
@ -214,7 +214,7 @@ fn format(
wrong_type: val.get_type().to_string(),
dst_span: head_span,
src_span: val.span(),
})
});
}
}
}

View File

@ -1,4 +1,4 @@
use nu_cmd_base::input_handler::{operate, CellPathOnlyArgs};
use nu_cmd_base::input_handler::{CellPathOnlyArgs, operate};
use nu_engine::command_prelude::*;
#[derive(Clone)]

View File

@ -14,7 +14,7 @@ pub use snake_case::StrSnakeCase;
pub use str_::Str;
pub use title_case::StrTitleCase;
use nu_cmd_base::input_handler::{operate as general_operate, CmdArgument};
use nu_cmd_base::input_handler::{CmdArgument, operate as general_operate};
use nu_engine::command_prelude::*;
struct Arguments<F: Fn(&str) -> String + Send + Sync + 'static> {