# Struct deranged::OptionRangedI16

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

## Expand description

A `RangedI16`

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

with niche value optimization.

If `MIN`

is `i16::MIN`

*and* `MAX`

is `i16::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 `OptionRangedI16::get`

.

## Implementations§

source§### impl<const MIN: i16, const MAX: i16> OptionRangedI16<MIN, MAX>

### impl<const MIN: i16, const MAX: i16> OptionRangedI16<MIN, MAX>

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

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

Creates an optional ranged value that is present.

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

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

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

type.

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

#### pub const unsafe fn some_unchecked(value: i16) -> 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: i16, const MAX: i16> Clone for OptionRangedI16<MIN, MAX>

### impl<const MIN: i16, const MAX: i16> Clone for OptionRangedI16<MIN, MAX>

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

#### fn clone(&self) -> OptionRangedI16<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: i16, const MAX: i16> From<Option<RangedI16<MIN, MAX>>> for OptionRangedI16<MIN, MAX>

### impl<const MIN: i16, const MAX: i16> From<Option<RangedI16<MIN, MAX>>> for OptionRangedI16<MIN, MAX>

source§### impl<const MIN: i16, const MAX: i16> From<OptionRangedI16<MIN, MAX>> for Option<RangedI16<MIN, MAX>>

### impl<const MIN: i16, const MAX: i16> From<OptionRangedI16<MIN, MAX>> for Option<RangedI16<MIN, MAX>>

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

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

source§### impl<const MIN: i16, const MAX: i16> Ord for OptionRangedI16<MIN, MAX>

### impl<const MIN: i16, const MAX: i16> Ord for OptionRangedI16<MIN, MAX>

source§### impl<const MIN_A: i16, const MAX_A: i16, const MIN_B: i16, const MAX_B: i16> PartialEq<OptionRangedI16<MIN_B, MAX_B>> for OptionRangedI16<MIN_A, MAX_A>

### impl<const MIN_A: i16, const MAX_A: i16, const MIN_B: i16, const MAX_B: i16> PartialEq<OptionRangedI16<MIN_B, MAX_B>> for OptionRangedI16<MIN_A, MAX_A>

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

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

`self`

and `other`

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

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

### impl<const MIN_A: i16, const MAX_A: i16, const MIN_B: i16, const MAX_B: i16> PartialOrd<OptionRangedI16<MIN_B, MAX_B>> for OptionRangedI16<MIN_A, MAX_A>

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

#### fn partial_cmp(&self, other: &OptionRangedI16<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