pub struct State<'s, T: 'static> { /* private fields */ }Expand description
A guard over one use_state slot.
Derefs to T, so *count += 1 works. The value lives in the store, so
nothing is written back on drop; the only thing drop does is request a
repaint if the value was mutably dereferenced.
Implementations§
Source§impl<'s, T: 'static> State<'s, T>
impl<'s, T: 'static> State<'s, T>
Sourcepub fn into_handle(self) -> Handle<'s, T>
pub fn into_handle(self) -> Handle<'s, T>
Consume the guard and return a Copy Handle to the same slot.
This releases the guard’s borrow. There is deliberately no
handle(&self): using a Handle while the guard is alive would
double-borrow the same RefCell and panic.
Sourcepub fn bind(&mut self) -> &mut T
pub fn bind(&mut self) -> &mut T
Hand &mut T to a widget that writes into it directly.
Unlike &mut *state this does not mark the state dirty, so a bound
widget does not ask for a repaint on every single frame. That is safe
because the widget only changes the value in response to input, and
input makes egui repaint anyway. This is what the bind prop of
TextEdit, Checkbox, Slider and ComboBox expects.
Sourcepub fn update_later(&self, f: impl FnOnce(&mut T) + 'static)
pub fn update_later(&self, f: impl FnOnce(&mut T) + 'static)
Queue a write for the end of the pass and request a repaint.
This is the way out of “the loop borrows the state, so the handler
inside it cannot”: todos.update_later(move |t| t.remove(i)). The
closure is 'static, so captures need move.
Calling this while the guard is alive is fine: the write happens long after the guard is gone.
Trait Implementations§
Auto Trait Implementations§
impl<'s, T> Freeze for State<'s, T>
impl<'s, T> !RefUnwindSafe for State<'s, T>
impl<'s, T> !Send for State<'s, T>
impl<'s, T> !Sync for State<'s, T>
impl<'s, T> Unpin for State<'s, T>
impl<'s, T> UnsafeUnpin for State<'s, T>
impl<'s, T> !UnwindSafe for State<'s, T>
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more