Skip to content

Commit d437997

Browse files
implement fromField
1 parent 815d461 commit d437997

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

wasm/src/types/field.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ impl Field {
9090
Field(self.0)
9191
}
9292

93+
/// Returns a reference to the inner native Field representation.
94+
/// Useful when calling Rust functions that operate on FieldNative directly.
95+
pub(crate) fn as_native(&self) -> &FieldNative {
96+
&self.0
97+
}
98+
9399
/// Generate a random field element.
94100
pub fn random() -> Field {
95101
let rng = &mut rand::thread_rng();

wasm/src/types/integer.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use snarkvm_console::prelude::{
2727
FromBytes, ToBytes, FromBits, ToBits,
2828
AbsChecked, AbsWrapped,
2929
AddWrapped, SubWrapped, MulWrapped, DivWrapped,
30-
RemWrapped, Pow, Rem,
30+
RemWrapped, Pow, Rem, FromField,
3131
};
3232

3333

@@ -152,13 +152,13 @@ macro_rules! impl_integer {
152152
crate::Scalar::from_native(self.0.to_scalar())
153153
}
154154

155-
// /// Convert from Field.
156-
// #[wasm_bindgen(js_name = "fromField")]
157-
// pub fn from_field(field: &crate::Field) -> Result<$name, String> {
158-
// <$native>::from_field(&field.0)
159-
// .map(Self)
160-
// .map_err(|e| e.to_string())
161-
// }
155+
/// Convert from Field.
156+
#[wasm_bindgen(js_name = "fromField")]
157+
pub fn from_field(field: &crate::Field) -> Result<$name, String> {
158+
<$native>::from_field(field.as_native())
159+
.map(Self)
160+
.map_err(|e| e.to_string())
161+
}
162162

163163
// /// Convert from Fields.
164164
// #[wasm_bindgen(js_name = "fromFields")]

0 commit comments

Comments
 (0)