@@ -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 , FromField ,
30+ RemWrapped , Pow , Rem , FromField , FromFields ,
3131} ;
3232
3333
@@ -160,22 +160,22 @@ macro_rules! impl_integer {
160160 . map_err( |e| e. to_string( ) )
161161 }
162162
163- // /// Convert from Fields.
164- // #[wasm_bindgen(js_name = "fromFields")]
165- // pub fn from_fields(fields: js_sys::Array) -> Result<$name, String> {
166- // // Collect JsValue → Field
167- // let rust_fields: Result<Vec<_>, _> = fields.iter().map(|jsv| {
163+ /// Convert from Fields.
164+ #[ wasm_bindgen( js_name = "fromFields" ) ]
165+ pub fn from_fields( fields: js_sys:: Array ) -> Result <$name, String > {
166+ // Collect JsValue → Field
167+ let rust_fields: Result <Vec <_>, String > = fields. iter( ) . map( |jsv| {
168+ let field_str = jsv. as_string( ) . ok_or( "Expected string for Field" ) ?;
169+ let field: FieldNative = FieldNative :: from_str( & field_str) . map_err( |e| e. to_string( ) ) ?;
170+ Ok ( field)
171+ } ) . collect( ) ;
168172
169- // let field_str = jsv.as_string().ok_or("Expected string for Field")?;
170- // let field = FieldNative::from_str(&field_str).map_err(|e| e.to_string())?;
171- // Ok(field)
172- // }).collect();
173173
174- // let rust_fields = rust_fields?;
175- // <$native>::from_fields(&rust_fields)
176- // .map(Self)
177- // .map_err(|e| e.to_string())
178- // }
174+ let rust_fields = rust_fields?;
175+ <$native>:: from_fields( & rust_fields)
176+ . map( Self )
177+ . map_err( |e| e. to_string( ) )
178+ }
179179
180180 /// Clone.
181181 pub fn clone( & self ) -> $name {
0 commit comments