pub struct Entry<'a, R> { /* private fields */ }
Implementations§
Source§impl<'a, R> Entry<'a, R>where
R: Resource,
An entry to a resource container.
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> Freeze for Entry<'a, R>
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> 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
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which 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)
Converts
&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)
Converts
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.