pub trait Storage<T> {
// Required methods
fn capacity(&self) -> usize;
fn slice(&self, range: Range<usize>) -> &[T];
unsafe fn slice_mut_unchecked(&self, range: Range<usize>) -> &mut [T];
// Provided method
fn slice_mut(&mut self, range: Range<usize>) -> &mut [T] { ... }
}
Expand description
Storage for a contiguous array of items allowing mutable access to multiple ranges as long as they don’t overlap.
This is implemented for any type that implements AsRef<[UnsafeCell<T>]>
. No matter the backing
store, elements must be wrapped in some kind of cell, as this is the only safe way to get a
mutable reference to something through a non-mutable reference.
This is a low-level trait, and must be implemented carefully.
Required Methods§
Sourceunsafe fn slice_mut_unchecked(&self, range: Range<usize>) -> &mut [T]
unsafe fn slice_mut_unchecked(&self, range: Range<usize>) -> &mut [T]
Gets a mutable slice of elements in the range provided. The length of the slice will always match the length of the range. This function is unchecked and unsafe because it does not ensure there are no other references overlapping with the range, which is against Rust’s borrowing rules and is very unsafe!
This function does ensure the range is valid, however.
§Safety
No other slices that overlap with the range must exist for the duration of this slice’s lifetime.
§Panics
This function may panic if the range extends beyond the length of the array returned by
capacity
.