Simplify leading zero checks
This commit is contained in:
parent
b9b97bbb9d
commit
a331e5fd2c
1 changed files with 2 additions and 5 deletions
|
|
@ -12,7 +12,7 @@ use crate::fmt;
|
|||
use crate::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
||||
use crate::str::FromStr;
|
||||
|
||||
trait ReadNumberHelper: crate::marker::Sized + crate::cmp::PartialEq {
|
||||
trait ReadNumberHelper: crate::marker::Sized {
|
||||
const ZERO: Self;
|
||||
fn checked_mul(&self, other: u32) -> Option<Self>;
|
||||
fn checked_add(&self, other: u32) -> Option<Self>;
|
||||
|
|
@ -131,10 +131,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
if digit_count == 0 {
|
||||
None
|
||||
} else if !allow_zero_prefix
|
||||
&& has_leading_zero
|
||||
&& (result != T::ZERO || result == T::ZERO && digit_count > 1)
|
||||
{
|
||||
} else if !allow_zero_prefix && has_leading_zero && digit_count > 1 {
|
||||
None
|
||||
} else {
|
||||
Some(result)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue