Skip to main content

State

Struct State 

Source
pub struct State<T> { /* private fields */ }
Expand description

Handle to state created by use_state(). Access via .get(ui) / .get_mut(ui).

§Note on Copy

As of v0.20.0, State<T> is no longer Copy. The internal key may hold an owned String (for Context::use_state_keyed), which prevents trivial duplication. Existing call sites that use the handle locally (let s = ui.use_state(...); s.get(ui);) are unaffected — the handle is moved into closures or borrowed by reference. If you previously relied on implicit copy semantics, call .clone() explicitly.

Implementations§

Source§

impl<T: 'static> State<T>

Source

pub fn get<'a>(&self, ui: &'a Context) -> &'a T

Read the current value.

§Panics

Panics if this handle’s slot or id contains a different concrete type, which means positional hooks changed order or the same named/keyed id was reused with another T. Named and keyed handles also panic if their backing entry was removed before access. The message identifies the hook index or id and the expected type.

Source

pub fn get_mut<'a>(&self, ui: &'a mut Context) -> &'a mut T

Mutably access the current value.

§Panics

Panics under the same slot, id, and type-mismatch conditions as get.

Trait Implementations§

Source§

impl<T: Clone> Clone for State<T>

Source§

fn clone(&self) -> State<T>

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
Source§

impl<T: Debug> Debug for State<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Eq> Eq for State<T>

Source§

impl<T: PartialEq> PartialEq for State<T>

Source§

fn eq(&self, other: &State<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for State<T>

Auto Trait Implementations§

§

impl<T> Freeze for State<T>
where PhantomData<T>: Freeze,

§

impl<T> RefUnwindSafe for State<T>

§

impl<T> Send for State<T>
where PhantomData<T>: Send,

§

impl<T> Sync for State<T>
where PhantomData<T>: Sync,

§

impl<T> Unpin for State<T>
where PhantomData<T>: Unpin,

§

impl<T> UnsafeUnpin for State<T>

§

impl<T> UnwindSafe for State<T>

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.