alef 0.60.0

Opinionated polyglot binding generator for Rust libraries
Documentation
1
2
3
4
5
6
7
8
9
10
11
#[php(name = "from_json")]
pub fn from_json(json: String) -> PhpResult<Self> {
    let value: Self = serde_json::from_str(&json).map_err(|e| PhpException::default(e.to_string()))?;
    if !matches!(value.{{ tag_field }}_tag.as_str(), {{ allowed_tags }} ) {
        return Err(PhpException::default(format!(
            "Invalid {{ enum_name }} tag: {}",
            value.{{ tag_field }}_tag,
        )));
    }
    Ok(value)
}