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:
parent
3214c4d604
commit
e446ed929a
3 changed files with 14 additions and 10 deletions
|
@ -447,8 +447,8 @@ impl fmt::Display for Table {
|
||||||
while let Some((i, elem)) = col_iter.next() {
|
while let Some((i, elem)) = col_iter.next() {
|
||||||
let is_last_col = col_iter.peek().is_none();
|
let is_last_col = col_iter.peek().is_none();
|
||||||
|
|
||||||
match self.alignments[i] {
|
match self.alignments.get(i) {
|
||||||
Alignment::Left => {
|
Some(Alignment::Left) => {
|
||||||
if is_last_col {
|
if is_last_col {
|
||||||
// no trailing spaces in last column
|
// no trailing spaces in last column
|
||||||
write!(f, "{elem}")?;
|
write!(f, "{elem}")?;
|
||||||
|
@ -456,7 +456,10 @@ impl fmt::Display for Table {
|
||||||
write!(f, "{:<width$}", elem, width = self.widths[i])?;
|
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 {
|
if !is_last_col {
|
||||||
|
|
|
@ -381,10 +381,10 @@ fn expand_line(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
match buf[byte] {
|
match buf.get(byte) {
|
||||||
// always take exactly 1 byte in strict ASCII mode
|
// always take exactly 1 byte in strict ASCII mode
|
||||||
0x09 => Tab,
|
Some(0x09) => Tab,
|
||||||
0x08 => Backspace,
|
Some(0x08) => Backspace,
|
||||||
_ => Other,
|
_ => Other,
|
||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
|
|
|
@ -755,11 +755,11 @@ impl Stater {
|
||||||
let chars = format_str.chars().collect::<Vec<char>>();
|
let chars = format_str.chars().collect::<Vec<char>>();
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < bound {
|
while i < bound {
|
||||||
match chars[i] {
|
match chars.get(i) {
|
||||||
'%' => tokens.push(Self::handle_percent_case(
|
Some('%') => tokens.push(Self::handle_percent_case(
|
||||||
&chars, &mut i, bound, format_str,
|
&chars, &mut i, bound, format_str,
|
||||||
)?),
|
)?),
|
||||||
'\\' => {
|
Some('\\') => {
|
||||||
if use_printf {
|
if use_printf {
|
||||||
tokens.push(Self::handle_escape_sequences(
|
tokens.push(Self::handle_escape_sequences(
|
||||||
&chars, &mut i, bound, format_str,
|
&chars, &mut i, bound, format_str,
|
||||||
|
@ -768,7 +768,8 @@ impl Stater {
|
||||||
tokens.push(Token::Char('\\'));
|
tokens.push(Token::Char('\\'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c => tokens.push(Token::Char(c)),
|
Some(c) => tokens.push(Token::Char(*c)),
|
||||||
|
None => break,
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue