1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

clippy: replace vector indexing with safe .get() method

This commit is contained in:
Sylvestre Ledru 2025-06-28 10:13:21 +02:00
parent 3214c4d604
commit e446ed929a
3 changed files with 14 additions and 10 deletions

View file

@ -447,8 +447,8 @@ impl fmt::Display for Table {
while let Some((i, elem)) = col_iter.next() {
let is_last_col = col_iter.peek().is_none();
match self.alignments[i] {
Alignment::Left => {
match self.alignments.get(i) {
Some(Alignment::Left) => {
if is_last_col {
// no trailing spaces in last column
write!(f, "{elem}")?;
@ -456,7 +456,10 @@ impl fmt::Display for Table {
write!(f, "{:<width$}", elem, width = self.widths[i])?;
}
}
Alignment::Right => write!(f, "{:>width$}", elem, width = self.widths[i])?,
Some(Alignment::Right) => {
write!(f, "{:>width$}", elem, width = self.widths[i])?;
}
None => break,
}
if !is_last_col {

View file

@ -381,10 +381,10 @@ fn expand_line(
}
} else {
(
match buf[byte] {
match buf.get(byte) {
// always take exactly 1 byte in strict ASCII mode
0x09 => Tab,
0x08 => Backspace,
Some(0x09) => Tab,
Some(0x08) => Backspace,
_ => Other,
},
1,

View file

@ -755,11 +755,11 @@ impl Stater {
let chars = format_str.chars().collect::<Vec<char>>();
let mut i = 0;
while i < bound {
match chars[i] {
'%' => tokens.push(Self::handle_percent_case(
match chars.get(i) {
Some('%') => tokens.push(Self::handle_percent_case(
&chars, &mut i, bound, format_str,
)?),
'\\' => {
Some('\\') => {
if use_printf {
tokens.push(Self::handle_escape_sequences(
&chars, &mut i, bound, format_str,
@ -768,7 +768,8 @@ impl Stater {
tokens.push(Token::Char('\\'));
}
}
c => tokens.push(Token::Char(c)),
Some(c) => tokens.push(Token::Char(*c)),
None => break,
}
i += 1;
}