alef 0.103.8

Opinionated polyglot binding generator for Rust libraries
Documentation
pub struct {{ struct_name }} {
    php_obj: ext_php_rs::types::Zval,
    cached_name: String,
}

impl Clone for {{ struct_name }} {
    fn clone(&self) -> Self {
        Self {
            php_obj: self.php_obj.shallow_clone(),
            cached_name: self.cached_name.clone(),
        }
    }
}

impl std::fmt::Debug for {{ struct_name }} {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{{ struct_name }}")
    }
}

impl {{ struct_name }} {
    pub fn new(php_obj: &mut ext_php_rs::types::ZendObject) -> Self {
        let cached_name = php_obj
            .try_call_method("name", vec![])
            .ok()
            .and_then(|v| v.string())
            .unwrap_or("unknown".into())
            .to_string();
        Self {
            php_obj: {
                let mut owned = ext_php_rs::types::Zval::new();
                owned.set_object(php_obj);
                owned
            },
            cached_name,
        }
    }
}