Macro class_derives

Source
macro_rules! class_derives {
    ($type: ty) => { ... };
}
Expand description

Implements a set of traits required to convert types that implement RegisteredClass to and from ZendObjects and Zvals. Generally, this macro should not be called directly, as it is called on any type that uses the php_class macro.

The following traits are implemented:

  • FromZendObject for &'a T
  • FromZendObjectMut for &'a mut T
  • FromZval for &'a T
  • FromZvalMut for &'a mut T
  • IntoZendObject for T
  • IntoZval for T

These implementations are required while we wait on the stabilisation of specialisation.

ยงExamples

use ext_php_rs::class_derives;

struct Test {
    a: i32,
    b: i64
}

impl RegisteredClass for Test {
    const CLASS_NAME: &'static str = "Test";

    const BUILDER_MODIFIER: Option<fn(ClassBuilder) -> ClassBuilder> = None;
    const EXTENDS: Option<ClassEntryInfo> = None;
    const IMPLEMENTS: &'static [ClassEntryInfo] =  &[];
    const FLAGS: ClassFlags = ClassFlags::empty();
    const DOC_COMMENTS: DocComments = &[];

    fn get_metadata() -> &'static ext_php_rs::class::ClassMetadata<Self> {
        todo!()
    }

    fn get_properties<'a>(
    ) -> std::collections::HashMap<&'static str, PropertyInfo<'a, Self>>
    {
        todo!()
    }

    fn method_builders() -> Vec<(FunctionBuilder<'static>, MethodFlags)> {
        todo!()
    }

    fn constructor() -> Option<ConstructorMeta<Self>> {
        todo!()
    }

    fn constants() -> &'static [(&'static str, &'static dyn IntoZvalDyn, DocComments)] {
        todo!()
    }
}

class_derives!(Test);

fn into_zval_test() -> Zval {
    let x = Test { a: 5, b: 10 };
    x.into_zval(false).unwrap()
}

fn from_zval_test<'a>(zv: &'a Zval) -> &'a Test {
    <&Test>::from_zval(zv).unwrap()
}