use crate::integer::Integer;
use crate::natural::Natural;
use core::ops::Neg;
use core::str::FromStr;
use malachite_base::num::conversion::traits::FromStringBase;
impl FromStr for Integer {
type Err = ();
#[inline]
fn from_str(s: &str) -> Result<Self, ()> {
Self::from_string_base(10, s).ok_or(())
}
}
impl FromStringBase for Integer {
#[inline]
fn from_string_base(base: u8, s: &str) -> Option<Self> {
if let Some(abs_string) = s.strip_prefix('-') {
if abs_string.starts_with('+') {
None
} else {
Natural::from_string_base(base, abs_string).map(Neg::neg)
}
} else {
Natural::from_string_base(base, s).map(Self::from)
}
}
}