Trait TrustedSizedCollection

Source
pub unsafe trait TrustedSizedCollection {
    // Required method
    fn len(&self) -> usize;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A sized collection.

This trait can be trusted by unsafe code thanks to the invariants below.

§Safety

Implementors of this trait must guarantee the following invariants:

  • The collection must hold a number of elements equal to len.
  • is_empty must return true if and only if len == 0 (in other words: collection.is_empty() == (collection.len() == 0)).

Required Methods§

Source

fn len(&self) -> usize

Returns the number of elements in the collection.

§Examples
let collection = vec![0; 5].into_par_index();
assert_eq!(collection.len(), 5);

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the collection has no elements in it.

Examples

let mut v = Vec::new();
{
    let collection = v.as_par_index();
    assert!(collection.is_empty());
}
v.push(42);
{
    let collection = v.as_par_index();
    assert!(!collection.is_empty());
}

Implementations on Foreign Types§

Source§

impl<T> TrustedSizedCollection for [T]

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

impl<T> TrustedSizedCollection for Vec<T>

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

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

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Implementors§