Skip to content

Commit

Permalink
Implement From<FqVector<Fp<P>>> for FpVector
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyBF committed Oct 4, 2024
1 parent d85f747 commit 32ae217
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ext/crates/fp/src/vector/fp_wrapper/macros_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ macro_rules! dispatch_vector {
}
}

macro_rules! impl_from {
() => {
impl From<FqVector<Fp<P2>>> for FpVector {
fn from(other: FqVector<Fp<P2>>) -> Self {
Self(other)
}
}
};
}

macro_rules! impl_try_into {
() => {
impl<'a> TryInto<&'a mut FqVector<Fp<P2>>> for &'a mut FpVector {
Expand Down
20 changes: 20 additions & 0 deletions ext/crates/fp/src/vector/fp_wrapper/macros_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,26 @@ macro_rules! dispatch_vector {
}
}

macro_rules! impl_from_inner {
($var:tt, $p:ty) => {
impl<'a> From<FqVector<Fp<$p>>> for FpVector {
fn from(x: FqVector<Fp<$p>>) -> Self {
FpVector::$var(x)
}
}
};
}

macro_rules! impl_from {
() => {
impl_from_inner!(_2, P2);
impl_from_inner!(_3, P3);
impl_from_inner!(_5, P5);
impl_from_inner!(_7, P7);
impl_from_inner!(Big, ValidPrime);
};
}

macro_rules! impl_try_into_inner {
($var:tt, $p:ty) => {
impl<'a> TryInto<&'a mut FqVector<Fp<$p>>> for &'a mut FpVector {
Expand Down
1 change: 1 addition & 0 deletions ext/crates/fp/src/vector/fp_wrapper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl<'a> IntoIterator for &'a FpVector {
}
}

impl_from!();
impl_try_into!();

impl Serialize for FpVector {
Expand Down

0 comments on commit 32ae217

Please sign in to comment.