Add support for constructing JsValue instances generically

This commit is contained in:
David Flemström
2018-03-28 01:22:31 +02:00
committed by Alex Crichton
parent e6a483f906
commit 73619b5d15
5 changed files with 86 additions and 4 deletions

View File

@ -88,6 +88,15 @@ pub struct CustomTypeName {
pub name: String,
}
pub fn new_function(struct_name: &str) -> String {
let mut name = format!("__wbg_");
name.extend(struct_name
.chars()
.flat_map(|s| s.to_lowercase()));
name.push_str("_new");
return name
}
pub fn free_function(struct_name: &str) -> String {
let mut name = format!("__wbg_");
name.extend(struct_name