Struct wayland_client::State
[−]
[src]
pub struct State { /* fields omitted */ }
A token store
This struct allows you to store various values in a store and access them back using the provided tokens.
Methods
impl Store
[src]
fn new() -> Store
[src]
Create a new store
fn insert<V>(&mut self, value: V) -> Token<V> where
V: 'static + Any,
[src]
V: 'static + Any,
Insert a new value in this store
Returns a clonable token that you can later use to access this value.
fn get<V>(&self, token: &Token<V>) -> &V where
V: 'static + Any,
[src]
V: 'static + Any,
Access value previously inserted in this store
Panics if the provided token corresponds to a value that was removed.
fn get_mut<V>(&mut self, token: &Token<V>) -> &mut V where
V: 'static + Any,
[src]
V: 'static + Any,
Mutably access value previously inserted in this store
Panics if the provided token corresponds to a value that was removed.
fn remove<V>(&mut self, token: Token<V>) -> V where
V: 'static + Any,
[src]
V: 'static + Any,
Remove a value previously inserted in this store
Panics if the provided token corresponds to a value that was already removed.
fn with_value<V, T, F>(&mut self, token: &Token<V>, f: F) -> T where
F: FnOnce(&mut StoreProxy, &mut V) -> T,
V: 'static + Any,
[src]
F: FnOnce(&mut StoreProxy, &mut V) -> T,
V: 'static + Any,
Create a sub-scope with access to a value
In the closure you provide, the value represented by token
will be available as an argument, as well as a StoreProxy
,
which allows you to manipulate the other values of the store
while this one is mutably borrowed.
Attempting to access again the same value from its token from within this closure is forbidden, and attempting to do so will result in a panic.
The StoreProxy
provides the same access methods as the Store
,
including with_value
, allowing you to create nested sub-scopes
accessing multiple store values at the same time.
fn as_proxy(&'a mut self) -> StoreProxy<'a>
[src]
See this Store
as a StoreProxy
with no ongoing borrow
This can be usefull for code requiering access to a store, but wanting to be generic over being called from a value scope or not.
You can also use the From
and Into
traits to perform
this conversion.