Crate range_checked
source ·Expand description
range-checked provides range checked types which leverage Rust’s type system to encode the bounds.
By encoding the bounds in the type, it is clear what values this type may have which may serve as a
useful invariant.
Example
This example shows how range-checked is seamlessly used with Rust’s conversion semantics. Note the third
generic type parameter, which controls if the upper bound is inclusive.
ⓘ
use range_checked::I32Bounded;
// Panics
let _: I32Bounded<0, 128, false> = 128.try_into().unwrap();
// Successful
let _: I32Bounded<0, 128, true> = 128.try_into().unwrap();
// Successful
let _: I32Bounded<0, 128, false> = 64.try_into().unwrap();Structs
- Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type. - Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type. - Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type. - Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type. - Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type. - Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type. - Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type. - Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type. - Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type. - Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type. - Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type. - Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type. - Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type. - Implements the
TryFromtype, which attempts to convert to the contained type, returning an error if the input is out of bounds. This type also implements [Deref] into the contained type.