Skip to main content

StateClass

Struct StateClass 

Source
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<[()]>

Source

pub fn from_name(name: impl Into<String>) -> Self

Create from name, which will be looked up from globals.

Source§

impl<T: ?Sized> StateClass<T>

Source

pub fn as_class_entry(&self) -> &ClassEntry

Converts to class entry.

Source§

impl<T: 'static> StateClass<T>

Source

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.

Source

pub fn init_object(&self) -> Result<StateObject<T>>

Create the object from class, without calling __construct.

Be careful when __construct is necessary.

Trait Implementations§

Source§

impl<T> Clone for StateClass<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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>
where T: Unpin + ?Sized,

§

impl<T> UnsafeUnpin for StateClass<T>
where T: ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.