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§
Sourceconst IS_SHRINKABLE: bool
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§
Required Methods§
Sourcefn get(&self, range: Range<usize>) -> Option<&[Self::Item]>
fn get(&self, range: Range<usize>) -> Option<&[Self::Item]>
Get an immutable slice of the elements within the specified range.
Sourcefn get_mut(&mut self, range: Range<usize>) -> Option<&mut [Self::Item]>
fn get_mut(&mut self, range: Range<usize>) -> Option<&mut [Self::Item]>
Get a mutable slice of the elements within the specified range.
Sourcefn shrink_container_to_range(
&mut self,
keep_range: Range<usize>,
) -> Option<Range<usize>>
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.