ext-php-rs icon indicating copy to clipboard operation
ext-php-rs copied to clipboard

class structs cannot contain class struct properties

Open ju1ius opened this issue 3 years ago • 0 comments

Hi, currently the following is not possible:

#[php_class]
struct Foo {
  #[prop]
  bar: Bar,
}

#[php_class]
#[derive(Clone)]
struct Bar {
  #[prop]
  value: String,
}
the trait bound `Bar: FromZval<'_>` is not satisfied
the trait `FromZval<'a>` is implemented for `&'a Bar`
required for `Bar` to implement `Prop<'_>`
required for the cast from `Bar` to the object type `dyn Prop<'_>` rustc(E0277)

This is supported in PyO3, from which this library seems to be inspired, so we should be able to do the same in ext_php_rs:

#[pyclass]
struct Foo {
  #[pyo3(get)]
  bar: Bar,
}

#[pyclass]
#[derive(Clone)]
struct Bar {
  #[pyo3(get)]
  value: String,
}

ju1ius avatar Nov 13 '22 18:11 ju1ius