pub struct Entry<'a, R> { /* private fields */ }
Implementations§
source§impl<'a, R> Entry<'a, R>where
R: Resource,
impl<'a, R> Entry<'a, R>where
R: Resource,
An entry to a resource container.
This is similar to the Entry API found in the standard library.
Examples
use rt_map::RtMap;
#[derive(Debug)]
struct Res(i32);
let mut rt_map = RtMap::<u32, Res>::default();
let value = rt_map.entry(0).or_insert(Res(4));
println!("{:?}", value.0 * 2);
sourcepub fn or_insert(self, v: R) -> RefMut<'a, R>
pub fn or_insert(self, v: R) -> RefMut<'a, R>
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.
sourcepub fn or_insert_with<F>(self, f: F) -> RefMut<'a, R>where
F: FnOnce() -> R,
pub fn or_insert_with<F>(self, f: F) -> RefMut<'a, R>where
F: FnOnce() -> R,
Returns this entry’s value, inserts and returns the return value of f
otherwise.
Auto Trait Implementations§
impl<'a, R> !RefUnwindSafe for Entry<'a, R>
impl<'a, R> Send for Entry<'a, R>where
R: Send,
impl<'a, R> Sync for Entry<'a, R>where
R: Sync,
impl<'a, R> Unpin for Entry<'a, R>where
R: Unpin,
impl<'a, R> !UnwindSafe for Entry<'a, R>
Blanket Implementations§
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.