Struct shred::Entry
[−]
[src]
pub struct Entry<'a, T: 'a> { /* fields omitted */ }
An entry to a resource of the Resources
struct.
This is similar to the Entry API found in the standard library.
Examples
use shred::Resources; #[derive(Debug)] struct Res(i32); let mut res = Resources::new(); let value = res.entry().or_insert(Res(4)); println!("{:?}", value.0 * 2);
Methods
impl<'a, T> Entry<'a, T> where
T: Resource + 'a,
[src]
T: Resource + 'a,
pub fn or_insert(self, v: T) -> FetchMut<'a, T>
[src]
Returns this entry's value, inserts and returns v
otherwise.
Please note that you should use or_insert_with
in case the creation of the
value is expensive.
pub fn or_insert_with<F>(self, f: F) -> FetchMut<'a, T> where
F: FnOnce() -> T,
[src]
F: FnOnce() -> T,
Returns this entry's value, inserts and returns the return value of f
otherwise.