Struct NonMaxUsize

struct NonMaxUsize(_)

A usize that can never be usize::MAX.

This is similar to core::num::NonZeroUsize, but instead of not permitting a zero value, this does not permit a max value.

This is useful in certain contexts where one wants to optimize the memory usage of things that contain match offsets. Namely, since Rust slices are guaranteed to never have a length exceeding isize::MAX, we can use usize::MAX as a sentinel to indicate that no match was found. Indeed, types like Option<NonMaxUsize> have exactly the same size in memory as a usize.

This type is defined to be repr(transparent) for core::num::NonZeroUsize, which is in turn defined to be repr(transparent) for usize.

Implementations

impl NonMaxUsize

fn new(value: usize) -> Option<NonMaxUsize>

Create a new NonMaxUsize from the given value.

This returns None only when the given value is equal to usize::MAX.

fn get(self: Self) -> usize

Return the underlying usize value. The returned value is guaranteed to not equal usize::MAX.

impl Clone for NonMaxUsize

fn clone(self: &Self) -> NonMaxUsize

impl Copy for NonMaxUsize

impl Debug for NonMaxUsize

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Eq for NonMaxUsize

impl Freeze for NonMaxUsize

impl Hash for NonMaxUsize

fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)

impl Ord for NonMaxUsize

fn cmp(self: &Self, other: &NonMaxUsize) -> Ordering

impl PartialEq for NonMaxUsize

fn eq(self: &Self, other: &NonMaxUsize) -> bool

impl PartialOrd for NonMaxUsize

fn partial_cmp(self: &Self, other: &NonMaxUsize) -> Option<Ordering>

impl RefUnwindSafe for NonMaxUsize

impl Send for NonMaxUsize

impl StructuralPartialEq for NonMaxUsize

impl Sync for NonMaxUsize

impl Unpin for NonMaxUsize

impl UnsafeUnpin for NonMaxUsize

impl UnwindSafe for NonMaxUsize

impl<T> Any for NonMaxUsize

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for NonMaxUsize

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for NonMaxUsize

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for NonMaxUsize

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for NonMaxUsize

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for NonMaxUsize

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for NonMaxUsize

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for NonMaxUsize

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for NonMaxUsize

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>