Skip to content

Conversation

davidcole1340
Copy link
Owner

Previously because of how mutably borrowing works in Rust, it wasn't (safely) possible to create an ArgParser as well as retrieve a reference to $this. This has been changed, and the ArgParser is now created by the execution data, returning the parser as well as a reference to $this.

Along with these changes, an Arg now stores a mutable zval reference. This shouldn't be a huge change since Arg is generally defined as mutable to be passed to ArgParser. This has allowed us to add two new traits: FromZvalMut and FromZendObjectMut, similar to FromZval and FromZendObject except that a mutable zval is provided, allowing us to extract mutable references to objects. If a type has FromZval implemented, then FromZvalMut is automatically implemented. The same goes for FromZendObject.

Since specialisation is not stabilised in Rust, the From{Zval, ZendObject}[Mut] and Into{Zval, ZendObject} traits cannot be generically implemented for types that implement RegisteredClass, as this collides with impl<T> FromZendObjectMut for T where T: FromZendObject. These implementations have been moved into the downstream extension crates, implemented using the class_derives! macro (which is automatically used on classes).

Closures can no longer be passed types that reference the zval, as it is consumed. Not sure why this happens, but had to use Zval::consume instead as lifetimes weren't being met.

Now stores a mutable reference to the underlying zval. Instead of
passing the execution data to the arg parser, a vector of args is now
passed to prevent a shared lifetime issue with the `$this` object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract &mut T from Zval and ZendObject ArgParser lifetimes are wrong Methods take &self but return &mut T

1 participant