Trait RcSliceContainer

Source
pub trait RcSliceContainer {
    type Item;

    const IS_SHRINKABLE: bool;

    // Required methods
    fn len(&self) -> usize;
    fn get(&self, range: Range<usize>) -> Option<&[Self::Item]>;
    fn get_mut(&mut self, range: Range<usize>) -> Option<&mut [Self::Item]>;
    fn shrink_container_to_range(
        &mut self,
        keep_range: Range<usize>,
    ) -> Option<Range<usize>>;
}
Expand description

Trait implemented by any RcSlice-able container. Currently implemented for arrays, boxed arrays, and vectors.

Required Associated Constants§

Source

const IS_SHRINKABLE: bool

The code to call shrink_container_to_range is somewhat expensive. Setting this constant to false allows the compiler to remove almost all of the RcSlice::shrink implementation.

Required Associated Types§

Source

type Item

The type of the elements in this container.

Required Methods§

Source

fn len(&self) -> usize

Return the total length of the container.

Source

fn get(&self, range: Range<usize>) -> Option<&[Self::Item]>

Get an immutable slice of the elements within the specified range.

Source

fn get_mut(&mut self, range: Range<usize>) -> Option<&mut [Self::Item]>

Get a mutable slice of the elements within the specified range.

Source

fn shrink_container_to_range( &mut self, keep_range: Range<usize>, ) -> Option<Range<usize>>

Shrink the container to just keep the specified range. Returns the new range if the container was completely or partially shrunk, or None if the container wasn’t modified.

If this returns a range then the new range MUST point the the same elements as keep_range.

If IS_SHRINKABLE is false, this function is never called, and implementations may panic.

The RcSlice implementation checks for the keep_range.len() == self.len() case, so implementations may omit special handling for it. The return value in that case may either be None or Some(keep_range) == Some(0..self.len()).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> RcSliceContainer for [T]

Source§

const IS_SHRINKABLE: bool = false

Source§

type Item = T

Source§

fn len(&self) -> usize

Source§

fn get(&self, range: Range<usize>) -> Option<&[T]>

Source§

fn get_mut(&mut self, range: Range<usize>) -> Option<&mut [T]>

Source§

fn shrink_container_to_range( &mut self, _keep_range: Range<usize>, ) -> Option<Range<usize>>

Source§

impl<T> RcSliceContainer for Box<[T]>

Source§

const IS_SHRINKABLE: bool = false

Source§

type Item = T

Source§

fn len(&self) -> usize

Source§

fn get(&self, range: Range<usize>) -> Option<&[Self::Item]>

Source§

fn get_mut(&mut self, range: Range<usize>) -> Option<&mut [Self::Item]>

Source§

fn shrink_container_to_range( &mut self, _keep_range: Range<usize>, ) -> Option<Range<usize>>

Source§

impl<T> RcSliceContainer for Vec<T>

Source§

const IS_SHRINKABLE: bool = true

Source§

type Item = T

Source§

fn len(&self) -> usize

Source§

fn get(&self, range: Range<usize>) -> Option<&[T]>

Source§

fn get_mut(&mut self, range: Range<usize>) -> Option<&mut [T]>

Source§

fn shrink_container_to_range( &mut self, keep_range: Range<usize>, ) -> Option<Range<usize>>

Implementors§