From 32ae21777b0e79e80eeab68209b2d6c308d454ce Mon Sep 17 00:00:00 2001 From: Joey Beauvais-Feisthauer Date: Fri, 4 Oct 2024 19:45:34 -0400 Subject: [PATCH] Implement `From>>` for `FpVector` --- .../fp/src/vector/fp_wrapper/macros_2.rs | 10 ++++++++++ .../src/vector/fp_wrapper/macros_generic.rs | 20 +++++++++++++++++++ ext/crates/fp/src/vector/fp_wrapper/mod.rs | 1 + 3 files changed, 31 insertions(+) diff --git a/ext/crates/fp/src/vector/fp_wrapper/macros_2.rs b/ext/crates/fp/src/vector/fp_wrapper/macros_2.rs index db8cd81aa..ef6dad1c4 100644 --- a/ext/crates/fp/src/vector/fp_wrapper/macros_2.rs +++ b/ext/crates/fp/src/vector/fp_wrapper/macros_2.rs @@ -117,6 +117,16 @@ macro_rules! dispatch_vector { } } +macro_rules! impl_from { + () => { + impl From>> for FpVector { + fn from(other: FqVector>) -> Self { + Self(other) + } + } + }; +} + macro_rules! impl_try_into { () => { impl<'a> TryInto<&'a mut FqVector>> for &'a mut FpVector { diff --git a/ext/crates/fp/src/vector/fp_wrapper/macros_generic.rs b/ext/crates/fp/src/vector/fp_wrapper/macros_generic.rs index 16a9becd7..bf07c7e37 100644 --- a/ext/crates/fp/src/vector/fp_wrapper/macros_generic.rs +++ b/ext/crates/fp/src/vector/fp_wrapper/macros_generic.rs @@ -216,6 +216,26 @@ macro_rules! dispatch_vector { } } +macro_rules! impl_from_inner { + ($var:tt, $p:ty) => { + impl<'a> From>> for FpVector { + fn from(x: FqVector>) -> 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>> for &'a mut FpVector { diff --git a/ext/crates/fp/src/vector/fp_wrapper/mod.rs b/ext/crates/fp/src/vector/fp_wrapper/mod.rs index 9fc62c920..b5ec22572 100644 --- a/ext/crates/fp/src/vector/fp_wrapper/mod.rs +++ b/ext/crates/fp/src/vector/fp_wrapper/mod.rs @@ -229,6 +229,7 @@ impl<'a> IntoIterator for &'a FpVector { } } +impl_from!(); impl_try_into!(); impl Serialize for FpVector {