Trait sentinel::Sentinel

source ·
pub unsafe trait Sentinel: Sized {
    type Unwrapped;

    const SENTINEL: Self = Self::SENTINEL;

    // Required method
    fn is_sentinel(this: &Self) -> bool;

    // Provided methods
    fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped> { ... }
    unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped { ... }
    unsafe fn find_sentinel_infinite(start: *const Self) -> usize { ... }
    fn find_sentinel(slice: &[Self]) -> Option<usize> { ... }
}
Expand description

Types which have a sentinel value.

Safety

The associated is_sentinel method must be pure. For any given input, it must either always return true, or always return false.

The associated find_sentinel method must be coherent with the is_sentinel method. It must return the smallest index such that evaluating is_sentinel on the value returns true. Same for find_sentinel_infinite.

SENTINEL must be a sentinel value. It must consistently return true when passed to is_sentinel.

Required Associated Types§

source

type Unwrapped

If the type has a special “unwrapped” version which does not include the sentinel value as a valid value, it should be defined here.

Provided Associated Constants§

source

const SENTINEL: Self = Self::SENTINEL

A sentinel value of this type.

Required Methods§

source

fn is_sentinel(this: &Self) -> bool

Determines whether value is a sentinel value.

Provided Methods§

source

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

Unwraps a non-sentinel value.

If the value is not a sentinel, [Some(_)] is returned.

source

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

Unwraps a non-sentinel value without checking whether it is actually a sentinel or not.

Safety

The provided this must not be a sentinel value.

source

unsafe fn find_sentinel_infinite(start: *const Self) -> usize

Returns the index of the first sentinel found starting at start.

Safety

A sentinel value must exist in the allocated object referenced by the pointer. Every element up to (and including) the sentinel, must be initialized and valid for reads.

source

fn find_sentinel(slice: &[Self]) -> Option<usize>

Returns the index of the first sentinel value of the provied slice.

If the sentinel is not found, None is returned.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Sentinel for bool

source§

const SENTINEL: Self = false

§

type Unwrapped = bool

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &bool) -> bool

source§

fn find_sentinel(slice: &[bool]) -> Option<usize>

source§

impl Sentinel for i8

source§

const SENTINEL: Self = 0i8

§

type Unwrapped = NonZeroI8

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &i8) -> bool

source§

fn find_sentinel(slice: &[i8]) -> Option<usize>

source§

impl Sentinel for i16

source§

const SENTINEL: Self = 0i16

§

type Unwrapped = i16

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &i16) -> bool

source§

impl Sentinel for i32

source§

const SENTINEL: Self = 0i32

§

type Unwrapped = i32

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &i32) -> bool

source§

impl Sentinel for i64

source§

const SENTINEL: Self = 0i64

§

type Unwrapped = i64

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &i64) -> bool

source§

impl Sentinel for i128

source§

const SENTINEL: Self = 0i128

§

type Unwrapped = i128

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &i128) -> bool

source§

impl Sentinel for isize

source§

const SENTINEL: Self = 0isize

§

type Unwrapped = isize

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &isize) -> bool

source§

impl Sentinel for u8

source§

const SENTINEL: Self = 0u8

§

type Unwrapped = NonZeroU8

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &u8) -> bool

source§

fn find_sentinel(slice: &[u8]) -> Option<usize>

source§

impl Sentinel for u16

source§

const SENTINEL: Self = 0u16

§

type Unwrapped = u16

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &u16) -> bool

source§

impl Sentinel for u32

source§

const SENTINEL: Self = 0u32

§

type Unwrapped = u32

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &u32) -> bool

source§

impl Sentinel for u64

source§

const SENTINEL: Self = 0u64

§

type Unwrapped = u64

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &u64) -> bool

source§

impl Sentinel for u128

source§

const SENTINEL: Self = 0u128

§

type Unwrapped = u128

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &u128) -> bool

source§

impl Sentinel for usize

source§

const SENTINEL: Self = 0usize

§

type Unwrapped = usize

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &usize) -> bool

source§

impl<T> Sentinel for Option<T>

source§

const SENTINEL: Self = None

§

type Unwrapped = T

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &Option<T>) -> bool

source§

impl<T> Sentinel for *const T

source§

const SENTINEL: Self = _

§

type Unwrapped = *const T

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &*const T) -> bool

source§

impl<T> Sentinel for *mut T

source§

const SENTINEL: Self = _

§

type Unwrapped = *mut T

source§

fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>

source§

unsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped

source§

fn is_sentinel(value: &*mut T) -> bool

Implementors§