[][src]Struct subset::multi::SubsetMut

pub struct SubsetMut<'a, T> { /* fields omitted */ }

Multi-subset of slice's items that is able to iterate forward and backward over references to selected items. Each item of a slice can be selected more than once.

The only difference between Subset and SubsetMut is that SubsetMut holds mutable reference to original set.

Methods

impl<'a, T> SubsetMut<'a, T>[src]

pub fn new(set: &'a mut [T], idxs: &'a [usize]) -> Result<Self, SubsetError>[src]

Constructs a multi-subset from the whole set and indexes of the selected items. Array bounds is checked. Note that subsets are not designed for ZSTs.

Examples

let mut set = [1, 2, 3];
let idxs = [0, 1];
let mut subset = SubsetMut::new(&mut set, &idxs).unwrap();
subset.set()[0] = 555;

Errors

OutOfBounds, if any index is >= set.len()

Panics

Panics if std::mem::size_of::<T>() == 0

pub unsafe fn new_unchecked(set: &'a mut [T], idxs: &'a [usize]) -> Self[src]

Constructs a multi-subset from the whole set and indexes of the selected items. No array bounds check.

pub fn set(&mut self) -> &mut [T][src]

Returns the original slice.

pub fn idxs(&self) -> &[usize][src]

Returns indexes of selected items.

pub fn is_unique(&self) -> bool[src]

Checks that no items are selected twice or more. if is_unique() == true then subset can be converted to unique::Subset or unique::SubsetMut.

Examples

 
let mut set = ["one".into(), "two", "three"];
let idxs = [0, 1];
let subset = SubsetMut::new(&mut set, &idxs).unwrap();
if subset.is_unique() {
    let uniq_subset: subset::unique::SubsetMut<_> = subset.try_into().unwrap();
}

pub unsafe fn to_unique_unchecked(self) -> Subset<'a, T>[src]

Converts to subset::unique::Subset. Uniqueness of indexes is not checked.

pub unsafe fn to_unique_mut_unchecked(self) -> SubsetMut<'a, T>[src]

Converts to subset::unique::SubsetMut. Uniqueness of indexes is not checked.

Important traits for Iter<'a, T>
pub fn iter(&self) -> Iter<T>[src]

Returns an iterator over immutable references to selected items.

Trait Implementations

impl<'a, T> IntoIterator for &'a SubsetMut<'a, T>[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<'a, T> From<SubsetMut<'a, T>> for Subset<'a, T>[src]

impl<'a, T> From<SubsetMut<'a, T>> for SubsetMut<'a, T>[src]

impl<'a, T: Debug> Debug for SubsetMut<'a, T>[src]

impl<'a, T> TryFrom<SubsetMut<'a, T>> for Subset<'a, T>[src]

type Error = SubsetError

The type returned in the event of a conversion error.

impl<'a, T> TryFrom<SubsetMut<'a, T>> for SubsetMut<'a, T>[src]

type Error = SubsetError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<'a, T> Send for SubsetMut<'a, T> where
    T: Send

impl<'a, T> Unpin for SubsetMut<'a, T>

impl<'a, T> Sync for SubsetMut<'a, T> where
    T: Sync

impl<'a, T> !UnwindSafe for SubsetMut<'a, T>

impl<'a, T> RefUnwindSafe for SubsetMut<'a, T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]