Struct HashMapChild

Source
pub struct HashMapChild<'a, K, T>(/* private fields */);

Implementations§

Source§

impl<'a, K, T> HashMapChild<'a, K, T>
where K: Hash + Eq + Clone, T: StaticType,

Source

pub fn contains_key<Q>(&self, k: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns true if the map contains a value for the specified key.

let mut map = HashMapOwner::new();
let mut map = map.child();
let value = map.insert("10".to_string(), Box::new(10));
assert!(map.contains_key("10"));
Source

pub fn try_insert(&mut self, key: K, v: T) -> Option<&'a T::Ref>

Tries to insert key and value if key already exists returns None

Else returns a reference to the inserted value without using the current lifetime

let mut map = HashMapOwner::new();
let mut map = map.child();
let v1 = map.try_insert("10", Box::new(10)).unwrap();
let v2 = map.try_insert("20", Box::new(20)).unwrap();
assert_eq!(*v1, 10);
assert_eq!(*v2, 20);
Source

pub fn insert(&mut self, key: K, v: T) -> &'a T::Ref

Insert key and value to the owner

Else returns a reference to the inserted value without using the current lifetime

§Panics

Panics if key already exists

let mut map = HashMapOwner::new();
let mut map = map.child();
let v1 = map.insert("10", Box::new(10));
let v2 = map.insert("20", Box::new(20));
assert_eq!(*v1, 10);
assert_eq!(*v2, 20);

Trait Implementations§

Source§

impl<'a, K: Debug, T: Debug> Debug for HashMapChild<'a, K, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, K, T> Freeze for HashMapChild<'a, K, T>

§

impl<'a, K, T> RefUnwindSafe for HashMapChild<'a, K, T>

§

impl<'a, K, T> Send for HashMapChild<'a, K, T>
where K: Send, T: Send,

§

impl<'a, K, T> Sync for HashMapChild<'a, K, T>
where K: Sync, T: Sync,

§

impl<'a, K, T> Unpin for HashMapChild<'a, K, T>

§

impl<'a, K, T> !UnwindSafe for HashMapChild<'a, K, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.