You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rust's HashMap type gets translated to the Map type in typescript. It is possible to use a struct containing a map as a parameter. However the generated glue code incorrectly uses JSON.stringify to convert the parameter into a string. This doesn't work on the Map member as the contained values are ignored. The code thus outputs an empty objects which doesn't contain the values of the Map.
Rust code:
use deno_bindgen::deno_bindgen;use std::collections::HashMap;#[deno_bindgen]structMyStruct{my_map:HashMap<String,String>,}#[deno_bindgen]fnmy_fn(my_struct:MyStruct){println!("{:?}", my_struct.my_map);}
This could be mitigated by using Record<T, U> instead of Map<T, U> as it refers to a plain JS-Object which can be properly converted by JSON.stringify.
The text was updated successfully, but these errors were encountered:
Rust's
HashMap
type gets translated to theMap
type in typescript. It is possible to use a struct containing a map as a parameter. However the generated glue code incorrectly usesJSON.stringify
to convert the parameter into a string. This doesn't work on theMap
member as the contained values are ignored. The code thus outputs an empty objects which doesn't contain the values of theMap
.Rust code:
Generated binding for struct:
Faulty binding using
JSON.stringify
:As such the follow code will not output
{a:'b'}
but instead{}
.This could be mitigated by using
Record<T, U>
instead ofMap<T, U>
as it refers to a plain JS-Object which can be properly converted byJSON.stringify
.The text was updated successfully, but these errors were encountered: