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>
impl<T: 'static> State<T>
Sourcepub fn get<'a>(&self, ui: &'a Context) -> &'a T
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.