Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ArgParser lifetimes #100

Merged
merged 2 commits into from
Oct 6, 2021
Merged

Fixed ArgParser lifetimes #100

merged 2 commits into from
Oct 6, 2021

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
1 participant