pub struct StateClass<T: ?Sized> { /* private fields */ }Expand description
The StateClass holds zend_class_entry and inner state, created by Module::add_class or ClassEntity::bound_class.
When the class registered (module initialized), the StateClass will be initialized, so you can use the StateClass to new stateful object, etc.
So, You shouldn’t use StateClass in module_init stage, because it
hasn’t initialized.
§Examples
use phper::{
classes::{ClassEntity, StateClass},
modules::Module,
php_get_module,
};
#[derive(Default)]
pub struct FooState;
fn make_foo_class() -> ClassEntity<FooState> {
ClassEntity::new_with_default_state_constructor("Foo")
}
#[php_get_module]
pub fn get_module() -> Module {
let mut module = Module::new(
env!("CARGO_CRATE_NAME"),
env!("CARGO_PKG_VERSION"),
env!("CARGO_PKG_AUTHORS"),
);
let _foo_class: StateClass<FooState> = module.add_class(make_foo_class());
module
}Implementations§
Source§impl StateClass<[()]>
impl StateClass<[()]>
Source§impl<T: ?Sized> StateClass<T>
impl<T: ?Sized> StateClass<T>
Sourcepub fn as_class_entry(&self) -> &ClassEntry
pub fn as_class_entry(&self) -> &ClassEntry
Converts to class entry.
Source§impl<T: 'static> StateClass<T>
impl<T: 'static> StateClass<T>
Sourcepub fn new_object(
&self,
arguments: impl AsMut<[ZVal]>,
) -> Result<StateObject<T>>
pub fn new_object( &self, arguments: impl AsMut<[ZVal]>, ) -> Result<StateObject<T>>
Create the object from class and call __construct with arguments.
If the __construct is private, or protected and the called scope isn’t
parent class, it will throw PHP Error.
Sourcepub fn init_object(&self) -> Result<StateObject<T>>
pub fn init_object(&self) -> Result<StateObject<T>>
Create the object from class, without calling __construct.
Be careful when __construct is necessary.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for StateClass<T>
impl<T> !Send for StateClass<T>
impl<T> !Sync for StateClass<T>
impl<T> !UnwindSafe for StateClass<T>
impl<T> Freeze for StateClass<T>where
T: ?Sized,
impl<T> Unpin for StateClass<T>
impl<T> UnsafeUnpin for StateClass<T>where
T: ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more