[−][src]Struct bank_vault::Vault
Implementations
impl<T> Vault<T>
[src]
pub fn new() -> Vault<T>
[src]
pub fn add(&self, to_add: T) -> VaultKey
[src]
Adds an object to the vault and returns a key.
Example
let vault = Vault::<i32>::new(); let key = vault.add(1);
pub fn remove(&self, key: &VaultKey) -> Option<T>
[src]
Removes and returns the stored object with a matching key, if it exists, otherwise returns None.
Example
let vault = Vault::<i32>::new(); let key = vault.add(1); let item = vault.remove(&key); assert_eq!(Some(1), item);
pub fn has_item(&self, key: &VaultKey) -> bool
[src]
Returns true if there exists an item in the vault with the provided key, otherwise returns false.
Example
let vault = Vault::<i32>::new(); let key = vault.add(1); let has_item = vault.has_item(&key); assert_eq!(true, has_item);
pub fn add_with_key(&self, to_add: T, key: &VaultKey) -> bool
[src]
Adds an item to the vault with the specified key. If the key already is in use, the item is not added and this returns false. If the key is not already in use, the item is added and returns true.
Example
let vault = Vault::<i32>::new(); let key = VaultKey::new(); let is_true = vault.add_with_key(1, &key); assert_eq!(true, is_true); let is_false = vault.add_with_key(2, &key); assert_eq!(false, is_false);
pub fn update_item<F>(&self, key: &VaultKey, operation: F) -> bool where
F: FnMut(T) -> T,
[src]
F: FnMut(T) -> T,
Updates an item in the vault with the specified key by applying the operation to it. Returns false if an item with the key is not found, otherwise returns true.
Example
let vault = Vault::<i32>::new(); let key = vault.add(1); let double_me = |i:i32| i * 2; let updated = vault.update_item(&key, double_me); assert_eq!(true, updated);
pub fn clear(&self)
[src]
Clears the contents of the vault.
Example
let vault = Vault::<i32>::new(); let key = vault.add(1); vault.clear(); let has_item = vault.has_item(&key); assert_eq!(false, has_item);
Auto Trait Implementations
impl<T> RefUnwindSafe for Vault<T>
[src]
impl<T> Send for Vault<T> where
T: Send,
[src]
T: Send,
impl<T> Sync for Vault<T> where
T: Send,
[src]
T: Send,
impl<T> Unpin for Vault<T> where
T: Unpin,
[src]
T: Unpin,
impl<T> UnwindSafe for Vault<T>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,