-
Notifications
You must be signed in to change notification settings - Fork 76
Add support for Enums #302
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
base: master
Are you sure you want to change the base?
Conversation
This adds an EnumBuilder to create PHP enums, and a `#[php_enum]` macro which you can attach to Rust enums. Only symbolic enums are supported from Rust. PHP doesn't support enums that hold data. They do support scalar backend-enums, however Rust does not support that. So, the `#[php_enum]` can only be used for non-backed enums. You can implement backed enums via the EnumBuilder in cses where you'd want to implement your own IntoZval / FromZval for your name and do something custom with the backed value. We could potentially add attributes to the enum for their string / int scale values in PHP though. I've added cfg php8.1 to this, as enums are only supported in PHP >= 8.1. I think it's better to conintue supporting PHP 8.0 for the time being, and just have the enums only be available in >= php 8.1.
@joehoyle PHP's backed enums are totally supported in Rust ;-)
Or just https://docs.rs/strum/latest/strum/derive.EnumString.html |
@Xenira what do you think about this PR? It it salvageable? |
@kakserpom maybe. Want to finish next release first though. But enums are high on the list of stuff to do next. |
Had a look and will rebuild this using changes from this MR, as that will probably be easier. A lot of the macro stuff has changed. |
This adds an EnumBuilder to create PHP enums, and a
#[php_enum]
macro which you can attach to Rust enums.Only symbolic enums are supported from Rust. PHP doesn't support enums that hold data. They do support scalar backend-enums, however Rust does not support that. So, the
#[php_enum]
can only be used for non-backed enums. You can implement backed enums via the EnumBuilder in cses where you'd want to implement your own IntoZval / FromZval for your name and do something custom with the backed value.We could potentially add attributes to the enum for their string / int scale values in PHP though.
I've added cfg php8.1 to this, as enums are only supported in PHP >= 8.1. I think it's better to conintue supporting PHP 8.0 for the time being, and just have the enums only be available in >= php 8.1.