Trait flatk::Isolate[][src]

pub trait Isolate<I> {
    type Output;
    unsafe fn isolate_unchecked(self, idx: I) -> Self::Output;
fn try_isolate(self, idx: I) -> Option<Self::Output>; fn isolate(self, idx: I) -> Self::Output
    where
        Self: Sized
, { ... } }
Expand description

Since we cannot alias mutable references, in order to index a mutable view of elements, we must consume the original mutable reference. Since we can’t use slices for general composable collections, its impossible to match against a &mut self in the getter function to be able to use it with owned collections, so we opt to have an interface that is designed specifically for mutably borrowed collections. For composable collections, this is better described by a subview operator, which is precisely what this trait represents. Incidentally this can also work for owned collections, which is why it’s called Isolate instead of SubView.

Associated Types

Required methods

Unchecked version of isolate.

Safety

The given index must be within the bounds of this collection, otherwise this function may cause undefined behaviour (UB). In otherwords try_isolate(idx) must not be None when called with the same idx to avoid UB.

Provided methods

Return a value at the given index. This is provided as the checked version of try_isolate that will panic if the equivalent try_isolate call is None, which typically means that the given index is out of bounds.

Panics

This function will panic if self.get(idx) returns None.

Implementors

A blanket implementation of Isolate for any collection which has an implementation for IsolateIndex.