Skip to content

Commit 3909c43

Browse files
bcmyersThomas Bahn
authored and
Thomas Bahn
committed
Clearer code but no behavior change for visit_str method
1 parent e92c948 commit 3909c43

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/serialization/ascii_char.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ impl<'de> Visitor<'de> for AsciiCharVisitor {
2828

2929
#[inline]
3030
fn visit_str<E: Error>(self, v: &str) -> Result<Self::Value, E> {
31-
let mut iter = v.chars();
32-
match (iter.next(), iter.next()) {
33-
(Some(c), None) => self.visit_char(c),
34-
_ => Err(Error::invalid_value(Unexpected::Str(v), &self)),
31+
if v.len() == 1 {
32+
let c = v.chars().next().unwrap();
33+
self.visit_char(c)
34+
} else {
35+
Err(Error::invalid_value(Unexpected::Str(v), &self))
3536
}
3637
}
3738
}

0 commit comments

Comments
 (0)