Struct NonMaxUsize

#[repr(transparent)]
pub struct NonMaxUsize(/* private field */);

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) -> usize

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

Trait Implementations

impl Clone for NonMaxUsize

fn clone(&self) -> Self

impl Copy for NonMaxUsize

impl Debug for NonMaxUsize

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

impl Eq for NonMaxUsize

impl Hash for NonMaxUsize

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

impl Ord for NonMaxUsize

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

impl PartialEq for NonMaxUsize

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

impl PartialOrd for NonMaxUsize

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

impl StructuralPartialEq for NonMaxUsize

Auto Trait Implementations

impl Freeze for NonMaxUsize

impl RefUnwindSafe for NonMaxUsize

impl Send for NonMaxUsize

impl Sync for NonMaxUsize

impl Unpin for NonMaxUsize

impl UnsafeUnpin for NonMaxUsize

impl UnwindSafe for NonMaxUsize

Blanket Implementations

impl<T> Any for NonMaxUsize where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for NonMaxUsize where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for NonMaxUsize where T: ?Sized,

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

impl<T> CloneToUninit for NonMaxUsize where T: Clone,

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

impl<T> From<T> for NonMaxUsize

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for NonMaxUsize where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for NonMaxUsize where U: From<T>,

fn into(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<U> for NonMaxUsize where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for NonMaxUsize where U: TryFrom<T>,

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