Browse Source

Replace `get(0)` with `first()`

This fixes a clippy lint.
Nicholas Bishop 2 years ago
parent
commit
739036c4fc
1 changed files with 6 additions and 6 deletions
  1. 6 6
      src/parser.rs

+ 6 - 6
src/parser.rs

@@ -10,7 +10,7 @@ fn next_char(sub: &[u8]) -> &[u8] {
 /// Parse the [Flags field](https://en.wikipedia.org/wiki/Printf_format_string#Flags_field).
 fn parse_flags(mut sub: &[u8]) -> (Flags, &[u8]) {
     let mut flags: Flags = Flags::empty();
-    while let Some(&ch) = sub.get(0) {
+    while let Some(&ch) = sub.first() {
         flags.insert(match ch {
             b'-' => Flags::LEFT_ALIGN,
             b'+' => Flags::PREPEND_PLUS,
@@ -28,10 +28,10 @@ fn parse_flags(mut sub: &[u8]) -> (Flags, &[u8]) {
 /// Parse the [Width field](https://en.wikipedia.org/wiki/Printf_format_string#Width_field).
 unsafe fn parse_width<'a>(mut sub: &'a [u8], args: &mut VaList) -> (c_int, &'a [u8]) {
     let mut width: c_int = 0;
-    if sub.get(0) == Some(&b'*') {
+    if sub.first() == Some(&b'*') {
         return (args.arg(), next_char(sub));
     }
-    while let Some(&ch) = sub.get(0) {
+    while let Some(&ch) = sub.first() {
         match ch {
             // https://rust-malaysia.github.io/code/2020/07/11/faster-integer-parsing.html#the-bytes-solution
             b'0'..=b'9' => width = width * 10 + (ch & 0x0f) as c_int,
@@ -44,7 +44,7 @@ unsafe fn parse_width<'a>(mut sub: &'a [u8], args: &mut VaList) -> (c_int, &'a [
 
 /// Parse the [Precision field](https://en.wikipedia.org/wiki/Printf_format_string#Precision_field).
 unsafe fn parse_precision<'a>(sub: &'a [u8], args: &mut VaList) -> (Option<c_int>, &'a [u8]) {
-    match sub.get(0) {
+    match sub.first() {
         Some(&b'.') => {
             let (prec, sub) = parse_width(next_char(sub), args);
             (Some(prec), sub)
@@ -97,7 +97,7 @@ impl Length {
 
 /// Parse the [Length field](https://en.wikipedia.org/wiki/Printf_format_string#Length_field).
 fn parse_length(sub: &[u8]) -> (Length, &[u8]) {
-    match sub.get(0).copied() {
+    match sub.first().copied() {
         Some(b'h') => match sub.get(1).copied() {
             Some(b'h') => (Length::Char, sub.get(2..).unwrap_or(&[])),
             _ => (Length::Short, next_char(sub)),
@@ -155,7 +155,7 @@ pub unsafe fn format(
         let (precision, sub) = parse_precision(sub, &mut args);
         let (length, sub) = parse_length(sub);
         let ch = sub
-            .get(0)
+            .first()
             .unwrap_or(if next.is_some() { &b'%' } else { &0 });
         err!(handler(Argument {
             flags,