Trait splitmut::SplitMut [] [src]

pub unsafe trait SplitMut<K, V> {
    fn get1_mut(&mut self, k1: K) -> Option<&mut V>;
unsafe fn get1_unchecked_mut(&mut self, k1: K) -> &mut V; fn get2_mut(
        &mut self,
        k1: K,
        k2: K
    ) -> (Result<&mut V, SplitMutError>, Result<&mut V, SplitMutError>) { ... }
fn get3_mut(
        &mut self,
        k1: K,
        k2: K,
        k3: K
    ) -> (Result<&mut V, SplitMutError>, Result<&mut V, SplitMutError>, Result<&mut V, SplitMutError>) { ... }
fn get4_mut(
        &mut self,
        k1: K,
        k2: K,
        k3: K,
        k4: K
    ) -> (Result<&mut V, SplitMutError>, Result<&mut V, SplitMutError>, Result<&mut V, SplitMutError>, Result<&mut V, SplitMutError>) { ... }
fn get_muts(&mut self) -> GetMuts<K, V, Self> { ... }
fn get_mut_iter<I: Iterator<Item = K>>(
        &mut self,
        i: I
    ) -> GetMutIter<K, V, Self, I> { ... }
unsafe fn get2_unchecked_mut(&mut self, k1: K, k2: K) -> (&mut V, &mut V) { ... }
unsafe fn get3_unchecked_mut(
        &mut self,
        k1: K,
        k2: K,
        k3: K
    ) -> (&mut V, &mut V, &mut V) { ... }
unsafe fn get4_unchecked_mut(
        &mut self,
        k1: K,
        k2: K,
        k3: K,
        k4: K
    ) -> (&mut V, &mut V, &mut V, &mut V) { ... } }

Just add use splitmut::SplitMut; to have these methods working on mutable slices, Vec, VecDeque, HashMap and BTreeMap.

In case you want to implement SplitMut for your own collection, just implement get1_mut and get1_unchecked_mut and the other methods will be provided for you. If you do so, you must make sure that these functions do not mutate your collection in ways that would invalidate previously returned values from get1_mut and get1_unchecked_mut.

Required Methods

Wrapper for get_mut, used internally.

Wrapper for get_unchecked_mut, used internally.

Undefined behaviour

It is undefined behaviour to call this with a key that does not correspond to a value. You have been warned.

Provided Methods

Returns two mutable references to two distinct values within the same collection.

Returns three mutable references to three distinct values within the same collection.

Returns four mutable references to four distinct values within the same collection.

Returns any number mutable references to distinct values within the same collection. A HashSet is used internally to keep track of values already returned.

Example

use splitmut::SplitMut;

let mut h = vec!["Hello", "world", "!"];
let mut z = h.get_muts();
let a = z.at(0);
let b = z.at(1);
assert_eq!(a, Ok(&mut "Hello"));
assert_eq!(b, Ok(&mut "world"));

Returns an iterator adapter that maps from a K to a Result. A HashSet is used internally to keep track of values already returned.

Example

use std::collections::BTreeMap;
use splitmut::{SplitMut, SplitMutError};

let mut h = BTreeMap::new();
h.insert(String::from("borrow"), 1);   
h.insert(String::from("me"), 2);
let slice = ["me", "borrow", "me"];
let z: Vec<_> = h.get_mut_iter(slice.into_iter().map(|&k| k)).collect();
assert_eq!(&*z, [Ok(&mut 2), Ok(&mut 1), Err(SplitMutError::SameValue)]);

Returns two mutable references to two distinct values within the same collection.

Undefined behaviour

It is undefined behaviour to call this with a key that does not correspond to a value, or with keys pointing to the same value. You have been warned.

Returns three mutable references to three distinct values within the same collection.

Undefined behaviour

It is undefined behaviour to call this with a key that does not correspond to a value, or with any two keys pointing to the same value. You have been warned.

Returns four mutable references to four distinct values within the same collection.

Undefined behaviour

It is undefined behaviour to call this with a key that does not correspond to a value, or with any two keys pointing to the same value. You have been warned.

Implementations on Foreign Types

impl<'a, V> SplitMut<usize, V> for &'a mut [V]
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<'a, V> SplitMut<usize, V> for Vec<V>
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<'a, V> SplitMut<usize, V> for VecDeque<V>
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<'a, K: Hash + Eq + Borrow<Q>, Q: Hash + Eq + ?Sized, V, S: BuildHasher> SplitMut<&'a Q, V> for HashMap<K, V, S>
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<'a, K: Ord + Borrow<Q>, Q: Ord + ?Sized, V> SplitMut<&'a Q, V> for BTreeMap<K, V>
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

Implementors