@@ -4,7 +4,7 @@ use crate::{
44 builders:: FunctionBuilder ,
55 convert:: IntoZval ,
66 describe:: DocComments ,
7- enum_:: EnumCase ,
7+ enum_:: { Discriminant , EnumCase } ,
88 error:: Result ,
99 ffi:: { zend_enum_add_case, zend_register_internal_enum} ,
1010 flags:: { DataType , MethodFlags } ,
@@ -114,14 +114,7 @@ impl EnumBuilder {
114114 for case in self . cases {
115115 let name = ZendStr :: new_interned ( case. name , true ) ;
116116 let value = match & case. discriminant {
117- Some ( value) => {
118- let value: Zval = match value {
119- crate :: enum_:: Discriminant :: Int ( i) => i. into_zval ( false ) ?,
120- crate :: enum_:: Discriminant :: String ( s) => s. into_zval ( true ) ?,
121- } ;
122- let mut zv = core:: mem:: ManuallyDrop :: new ( value) ;
123- ( & raw mut zv) . cast ( )
124- }
117+ Some ( value) => Self :: create_enum_value ( value) ?,
125118 None => ptr:: null_mut ( ) ,
126119 } ;
127120 unsafe {
@@ -137,6 +130,16 @@ impl EnumBuilder {
137130
138131 Ok ( ( ) )
139132 }
133+
134+ fn create_enum_value ( discriminant : & Discriminant ) -> Result < * mut Zval > {
135+ let value: Zval = match discriminant {
136+ Discriminant :: Int ( i) => i. into_zval ( false ) ?,
137+ Discriminant :: String ( s) => s. into_zval ( true ) ?,
138+ } ;
139+
140+ let boxed_value = Box :: new ( value) ;
141+ Ok ( Box :: into_raw ( boxed_value) . cast ( ) )
142+ }
140143}
141144
142145#[ cfg( test) ]
0 commit comments