Skip to content

Commit

Permalink
Remove the FromStr implementation from DynamicModInt<_>
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Oct 4, 2020
1 parent 7f950ae commit 494bd4a
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/modint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ impl<M: Modulus> ModIntBase for StaticModInt<M> {
}
}

impl<M: Modulus> FromStr for StaticModInt<M> {
type Err = Infallible;

#[inline]
fn from_str(s: &str) -> Result<Self, Infallible> {
Ok(s.parse::<i64>()
.map(Self::new)
.unwrap_or_else(|_| todo!("parsing as an arbitrary precision integer?")))
}
}

/// Represents a modulus.
///
/// # Example
Expand Down Expand Up @@ -494,7 +505,6 @@ impl Default for Barrett {
/// [`DynamicModInt`]: ../struct.DynamicModInt.html
pub trait ModIntBase:
Default
+ FromStr
+ From<i8>
+ From<i16>
+ From<i32>
Expand Down Expand Up @@ -745,13 +755,6 @@ trait InternalImplementations: ModIntBase {
Self::raw(0)
}

#[inline]
fn from_str_impl(s: &str) -> Result<Self, Infallible> {
Ok(s.parse::<i64>()
.map(Self::new)
.unwrap_or_else(|_| todo!("parsing as an arbitrary precision integer?")))
}

#[inline]
fn hash_impl(this: &Self, state: &mut impl Hasher) {
this.val().hash(state)
Expand Down Expand Up @@ -824,15 +827,6 @@ macro_rules! impl_basic_traits {
}
}

impl <$generic_param: $generic_param_bound> FromStr for $self {
type Err = Infallible;

#[inline]
fn from_str(s: &str) -> Result<Self, Infallible> {
Self::from_str_impl(s)
}
}

impl<$generic_param: $generic_param_bound, V: RemEuclidU32> From<V> for $self {
#[inline]
fn from(from: V) -> Self {
Expand Down

0 comments on commit 494bd4a

Please sign in to comment.