@@ -221,18 +221,28 @@ fn php_class_internal(args: TokenStream2, input: TokenStream2) -> TokenStream2 {
221221///
222222/// Enums can be exported to PHP as enums with the `#[php_enum]` attribute
223223/// macro. This attribute derives the `RegisteredClass` and `PhpEnum` traits on
224- /// your enum. To register the enum use the `r#enum ::<EnumName>()` method on the
225- /// `ModuleBuilder` in the `#[php_module]` macro.
224+ /// your enum. To register the enum use the `enumeration ::<EnumName>()` method
225+ /// on the `ModuleBuilder` in the `#[php_module]` macro.
226226///
227227/// ## Options
228228///
229- /// tbd
229+ /// The `#[php_enum]` attribute can be configured with the following options:
230+ /// - `#[php(name = "EnumName")]` or `#[php(change_case = snake_case)]`: Sets
231+ /// the name of the enum in PHP. The default is the `PascalCase` name of the
232+ /// enum.
233+ /// - `#[php(allow_native_discriminants)]`: Allows the use of native Rust
234+ /// discriminants (e.g., `Hearts = 1`).
230235///
231- /// ## Restrictions
232- ///
233- /// tbd
236+ /// The cases of the enum can be configured with the following options:
237+ /// - `#[php(name = "CaseName")]` or `#[php(change_case = snake_case)]`: Sets
238+ /// the name of the enum case in PHP. The default is the `PascalCase` name of
239+ /// the case.
240+ /// - `#[php(discriminant = "value")]` or `#[php(discriminant = 123)]`: Sets the
241+ /// discriminant value for the enum case. This can be a string or an integer.
242+ /// If not set, the case will be exported as a simple enum case without a
243+ /// discriminant.
234244///
235- /// ## Example
245+ /// ### Example
236246///
237247/// This example creates a PHP enum `Suit`.
238248///
@@ -251,11 +261,72 @@ fn php_class_internal(args: TokenStream2, input: TokenStream2) -> TokenStream2 {
251261///
252262/// #[php_module]
253263/// pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
254- /// module.r#enum ::<Suit>()
264+ /// module.enumeration ::<Suit>()
255265/// }
256266/// # fn main() {}
257267/// ```
258268///
269+ /// ## Backed Enums
270+ /// Enums can also be backed by either `i64` or `&'static str`. Those values can
271+ /// be set using the `#[php(discriminant = "value")]` or `#[php(discriminant =
272+ /// 123)]` attributes on the enum variants.
273+ ///
274+ /// All variants must have a discriminant of the same type, either all `i64` or
275+ /// all `&'static str`.
276+ ///
277+ /// ```rust,no_run,ignore
278+ /// # #![cfg_attr(windows, feature(abi_vectorcall))]
279+ /// # extern crate ext_php_rs;
280+ /// use ext_php_rs::prelude::*;
281+ ///
282+ /// #[php_enum]
283+ /// pub enum Suit {
284+ /// #[php(discriminant = "hearts")]
285+ /// Hearts,
286+ /// #[php(discriminant = "diamonds")]
287+ /// Diamonds,
288+ /// #[php(discriminant = "clubs")]
289+ /// Clubs,
290+ /// #[php(discriminant = "spades")]
291+ /// Spades,
292+ /// }
293+ /// #[php_module]
294+ /// pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
295+ /// module.enumeration::<Suit>()
296+ /// }
297+ /// # fn main() {}
298+ /// ```
299+ ///
300+ /// ### 'Native' Discriminators
301+ /// Native rust discriminants are currently not supported and will not be
302+ /// exported to PHP.
303+ ///
304+ /// To avoid confusion a compiler error will be raised if you try to use a
305+ /// native discriminant. You can ignore this error by adding the
306+ /// `#[php(allow_native_discriminants)]` attribute to your enum.
307+ ///
308+ /// ```rust,no_run,ignore
309+ /// # #![cfg_attr(windows, feature(abi_vectorcall))]
310+ /// # extern crate ext_php_rs;
311+ /// use ext_php_rs::prelude::*;
312+ ///
313+ /// #[php_enum]
314+ /// #[php(allow_native_discriminants)]
315+ /// pub enum Suit {
316+ /// Hearts = 1,
317+ /// Diamonds = 2,
318+ /// Clubs = 3,
319+ /// Spades = 4,
320+ /// }
321+ ///
322+ /// #[php_module]
323+ /// pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
324+ /// module.enumeration::<Suit>()
325+ /// }
326+ /// # fn main() {}
327+ /// ```
328+ ///
329+ ///
259330/// TODO: Add backed enums example
260331// END DOCS FROM enum.md
261332#[ proc_macro_attribute]
0 commit comments