Trait slice_utils::ContiguousBorrowed

source ·
pub trait ContiguousBorrowed: SliceBorrowed + Unique {
    // Required method
    fn contiguous(&self) -> &[Self::Output];
}
Expand description

A slice whose backing is contiguous in memory.

See also ContiguousMut. Note that there’s no ContiguousOwned: this is because Rust does not (yet) allow you to use associated constants in const operations, so there is no way to return an array.

The alternative would be an “owning borrow”, where you return a slice that has permission to treat the referenced data like it owns it (because it does), but those are still imperfect.

Required Methods§

source

fn contiguous(&self) -> &[Self::Output]

Get the contiguous backing of this slice.

The returned slice should behave exactly like this one, e.g. self.get(n) == self.contiguous().get(n).

§Examples
let a = [1, 2, 3].to_vec();
let b = a.contiguous();

assert_eq!(a, b);

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<S> ContiguousBorrowed for &S

source§

fn contiguous(&self) -> &[S::Output]

source§

impl<S> ContiguousBorrowed for &mut S

source§

fn contiguous(&self) -> &[S::Output]

source§

impl<T> ContiguousBorrowed for [T]

source§

fn contiguous(&self) -> &[T]

source§

impl<T, const N: usize> ContiguousBorrowed for [T; N]

source§

fn contiguous(&self) -> &[T]

Implementors§