Trait crow_util::traits::GetTwo [−][src]
pub trait GetTwo<T> { fn get_two(
&mut self,
index_a: usize,
index_b: usize
) -> Option<(&mut T, &mut T)>; unsafe fn get_two_unchecked(
&mut self,
index_a: usize,
index_b: usize
) -> (&mut T, &mut T); }
Used to mutably borrow 2 elements from a collection at once.
Required Methods
fn get_two(
&mut self,
index_a: usize,
index_b: usize
) -> Option<(&mut T, &mut T)>
&mut self,
index_a: usize,
index_b: usize
) -> Option<(&mut T, &mut T)>
Mutably borrows 2 elements at once.
In case index_a
is equal to index_b
or one of them is out of bounds this function returns None
.
Examples
use crow_util::traits::*; let mut x = vec![0, 1, 2, 3, 4, 5]; assert_eq!(x.get_two(0, 3), Some((&mut 0, &mut 3))); assert_eq!(x.get_two(1, 1), None);
unsafe fn get_two_unchecked(
&mut self,
index_a: usize,
index_b: usize
) -> (&mut T, &mut T)
&mut self,
index_a: usize,
index_b: usize
) -> (&mut T, &mut T)
Mutably borrows 2 elements at once without checking if it is safe to do so.TakeTwo
This is genarally not recommended, use with caution! For a safe alternative see get_two
Examples
use crow_util::traits::*; let mut x = vec![0, 1, 2, 3, 4, 5]; assert_eq!(unsafe { x.get_two_unchecked(0, 3) }, (&mut 0, &mut 3));
Implementations on Foreign Types
impl<T> GetTwo<T> for Vec<T>
[src]
impl<T> GetTwo<T> for Vec<T>