Skip to content

implementing Interfaces #163

@nikeee

Description

@nikeee

The docs state:

#[implements(ce)] - Implements the given interface on the class. Can be used multiple times. ce must be a valid Rust expression when it is called inside the #[php_module] function.

How do I use this to implement an interface provided by the standard library of PHP? For example, I want to implement ArrayAccess on my own class.

My current approach is this:

#[php_class]
#[implements(ext_php_rs::zend::class::ClassEntry::try_find("ArrayAccess").unwrap())]
pub struct Test {
}

But the class type seems to be private:

error[E0603]: module `class` is private
   --> src/lib.rs:205:1

If I get this to work, how do I actually implement the methods? Does having the appropriate method names suffice (putting renaming of methods aside)?

If this has a solution, I'd love to contribute this to the docs. I really like this library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions