# Struct deranged::OptionRangedU16

source · `pub struct OptionRangedU16<const MIN: u16, const MAX: u16>(/* private fields */);`

## Expand description

A `RangedU16`

that is optional. Equivalent to `Option<RangedU16>`

with niche value optimization.

If `MIN`

is `u16::MIN`

*and* `MAX`

is `u16::MAX`

then compilation will fail. This is because there is no way to represent the niche value.

This type is useful when you need to store an optional ranged value in a struct, but
do not want the overhead of an `Option`

type. This reduces the size of the struct
overall, and is particularly useful when you have a large number of optional fields.
Note that most operations must still be performed on the `Option`

type, which is
obtained with `OptionRangedU16::get`

.

## Implementations§

source§### impl<const MIN: u16, const MAX: u16> OptionRangedU16<MIN, MAX>

### impl<const MIN: u16, const MAX: u16> OptionRangedU16<MIN, MAX>

source#### pub const fn Some(value: RangedU16<MIN, MAX>) -> Self

#### pub const fn Some(value: RangedU16<MIN, MAX>) -> Self

Creates an optional ranged value that is present.

source#### pub const fn get(self) -> Option<RangedU16<MIN, MAX>>

#### pub const fn get(self) -> Option<RangedU16<MIN, MAX>>

Returns the value as the standard library’s `Option`

type.

source#### pub const unsafe fn some_unchecked(value: u16) -> Self

#### pub const unsafe fn some_unchecked(value: u16) -> Self

Creates an optional ranged integer without checking the value.

##### §Safety

The value must be within the range `MIN..=MAX`

. As the value used for niche
value optimization is unspecified, the provided value must not be the niche
value.

## Trait Implementations§

source§### impl<const MIN: u16, const MAX: u16> Clone for OptionRangedU16<MIN, MAX>

### impl<const MIN: u16, const MAX: u16> Clone for OptionRangedU16<MIN, MAX>

source§#### fn clone(&self) -> OptionRangedU16<MIN, MAX>

#### fn clone(&self) -> OptionRangedU16<MIN, MAX>

1.0.0 · source§#### fn clone_from(&mut self, source: &Self)

#### fn clone_from(&mut self, source: &Self)

`source`

. Read moresource§### impl<const MIN: u16, const MAX: u16> From<Option<RangedU16<MIN, MAX>>> for OptionRangedU16<MIN, MAX>

### impl<const MIN: u16, const MAX: u16> From<Option<RangedU16<MIN, MAX>>> for OptionRangedU16<MIN, MAX>

source§### impl<const MIN: u16, const MAX: u16> From<OptionRangedU16<MIN, MAX>> for Option<RangedU16<MIN, MAX>>

### impl<const MIN: u16, const MAX: u16> From<OptionRangedU16<MIN, MAX>> for Option<RangedU16<MIN, MAX>>

source§#### fn from(value: OptionRangedU16<MIN, MAX>) -> Self

#### fn from(value: OptionRangedU16<MIN, MAX>) -> Self

source§### impl<const MIN: u16, const MAX: u16> Ord for OptionRangedU16<MIN, MAX>

### impl<const MIN: u16, const MAX: u16> Ord for OptionRangedU16<MIN, MAX>

source§### impl<const MIN_A: u16, const MAX_A: u16, const MIN_B: u16, const MAX_B: u16> PartialEq<OptionRangedU16<MIN_B, MAX_B>> for OptionRangedU16<MIN_A, MAX_A>

### impl<const MIN_A: u16, const MAX_A: u16, const MIN_B: u16, const MAX_B: u16> PartialEq<OptionRangedU16<MIN_B, MAX_B>> for OptionRangedU16<MIN_A, MAX_A>

source§#### fn eq(&self, other: &OptionRangedU16<MIN_B, MAX_B>) -> bool

#### fn eq(&self, other: &OptionRangedU16<MIN_B, MAX_B>) -> bool

`self`

and `other`

values to be equal, and is used
by `==`

.source§### impl<const MIN_A: u16, const MAX_A: u16, const MIN_B: u16, const MAX_B: u16> PartialOrd<OptionRangedU16<MIN_B, MAX_B>> for OptionRangedU16<MIN_A, MAX_A>

### impl<const MIN_A: u16, const MAX_A: u16, const MIN_B: u16, const MAX_B: u16> PartialOrd<OptionRangedU16<MIN_B, MAX_B>> for OptionRangedU16<MIN_A, MAX_A>

source§#### fn partial_cmp(&self, other: &OptionRangedU16<MIN_B, MAX_B>) -> Option<Ordering>

#### fn partial_cmp(&self, other: &OptionRangedU16<MIN_B, MAX_B>) -> Option<Ordering>

1.0.0 · source§#### fn le(&self, other: &Rhs) -> bool

#### fn le(&self, other: &Rhs) -> bool

`self`

and `other`

) and is used by the `<=`

operator. Read more