Trait 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);

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<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§