alef 0.110.2

Opinionated polyglot binding generator for Rust libraries
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
pub struct {{ enum_name }}(pub {{ source_path }});

impl From<{{ source_path }}> for {{ enum_name }} {
    fn from(val: {{ source_path }}) -> Self {
        Self(val)
    }
}

impl {{ enum_name }} {
    pub fn to_string(&self) -> String {
        serde_json::to_string(&self.0).expect("serializable {{ enum_name }}")
    }
}

#[allow(dead_code)]
fn {{ fn_name }}(value: &str) -> Result<{{ source_path }}, String> {
    serde_json::from_str::<{{ source_path }}>(value).map_err(|error| error.to_string())
}