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 2, 2020
1 parent 3056e2a commit 93454cf
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 @@ -114,6 +114,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?")))
}
}

pub trait Modulus: 'static + Copy + Eq {
const VALUE: u32;
const HINT_VALUE_IS_PRIME: bool;
Expand Down Expand Up @@ -273,7 +284,6 @@ impl Default for Barrett {

pub trait ModIntBase:
Default
+ FromStr
+ From<i8>
+ From<i16>
+ From<i32>
Expand Down Expand Up @@ -400,13 +410,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 @@ -479,15 +482,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 93454cf

Please sign in to comment.