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§
Provided Associated Constants§
Required Methods§
sourcefn is_sentinel(this: &Self) -> bool
fn is_sentinel(this: &Self) -> bool
Determines whether value
is a sentinel value.
Provided Methods§
sourcefn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>
fn unwrap_sentinel(this: Self) -> Option<Self::Unwrapped>
Unwraps a non-sentinel value.
If the value is not a sentinel, [Some(_)
] is returned.
sourceunsafe fn unwrap_sentinel_unchecked(this: Self) -> Self::Unwrapped
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.
sourceunsafe fn find_sentinel_infinite(start: *const Self) -> usize
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.