Fixed clippy errors

This commit is contained in:
Simon Curtis 2024-12-19 14:01:10 +00:00
parent 69f373850f
commit cac6998708
2 changed files with 23 additions and 4 deletions

View File

@ -140,7 +140,25 @@ fn map_value(input: &Value, args: &Arguments, head: Span) -> Value {
match input { match input {
Value::Binary { val, .. } => { Value::Binary { val, .. } => {
let len = val.len() as u64; let len = val.len() as u64;
let start: usize = range.absolute_start(len).try_into().unwrap(); let start: u64 = range.absolute_start(len);
let start: usize = match start.try_into() {
Ok(start) => start,
Err(_) => {
let span = input.span();
return Value::error(
ShellError::UnsupportedInput {
msg: format!(
"Absolute start position {start} was too large for your system arch."
),
input: args.range.to_string(),
msg_span: span,
input_span: span,
},
head,
);
}
};
let bytes: Vec<u8> = match range.absolute_end(len) { let bytes: Vec<u8> = match range.absolute_end(len) {
Bound::Unbounded => val[start..].into(), Bound::Unbounded => val[start..].into(),
Bound::Included(end) => val[start..=end as usize].into(), Bound::Included(end) => val[start..=end as usize].into(),

View File

@ -81,10 +81,11 @@ mod int_range {
self.start self.start
} }
// Resolves the absolute start position given the length of the input value
pub fn absolute_start(&self, len: u64) -> u64 { pub fn absolute_start(&self, len: u64) -> u64 {
let max_index = len - 1; let max_index = len - 1;
match self.start { match self.start {
start if start < 0 => len.saturating_sub(start.unsigned_abs().into()), start if start < 0 => len.saturating_sub(start.unsigned_abs()),
start => max_index.min(start as u64), start => max_index.min(start as u64),
} }
} }
@ -110,11 +111,11 @@ mod int_range {
match self.end { match self.end {
Bound::Unbounded => Bound::Unbounded, Bound::Unbounded => Bound::Unbounded,
Bound::Included(i) => Bound::Included(match i { Bound::Included(i) => Bound::Included(match i {
i if i < 0 => len.saturating_sub(i.unsigned_abs() as u64), i if i < 0 => len.saturating_sub(i.unsigned_abs()),
i => max_index.min(i as u64), i => max_index.min(i as u64),
}), }),
Bound::Excluded(i) => Bound::Excluded(match i { Bound::Excluded(i) => Bound::Excluded(match i {
i if i < 0 => len.saturating_sub(i.unsigned_abs() as u64), i if i < 0 => len.saturating_sub(i.unsigned_abs()),
i => len.min(i as u64), i => len.min(i as u64),
}), }),
} }