diff --git a/src/bigint/convert.rs b/src/bigint/convert.rs index 9c7ab55e..d0e28b67 100644 --- a/src/bigint/convert.rs +++ b/src/bigint/convert.rs @@ -25,8 +25,7 @@ impl Num for BigInt { /// Creates and initializes a [`BigInt`]. #[inline] fn from_str_radix(mut s: &str, radix: u32) -> Result { - let sign = if s.starts_with('-') { - let tail = &s[1..]; + let sign = if let Some(tail) = s.strip_prefix('-') { if !tail.starts_with('+') { s = tail } diff --git a/src/biguint/convert.rs b/src/biguint/convert.rs index a81778c8..3daf3dcb 100644 --- a/src/biguint/convert.rs +++ b/src/biguint/convert.rs @@ -221,8 +221,7 @@ impl Num for BigUint { fn from_str_radix(s: &str, radix: u32) -> Result { assert!(2 <= radix && radix <= 36, "The radix must be within 2...36"); let mut s = s; - if s.starts_with('+') { - let tail = &s[1..]; + if let Some(tail) = s.strip_prefix('+') { if !tail.starts_with('+') { s = tail }