pub struct BoundedInt32<const LOWER: i32, const UPPER: i32> { /* private fields */ }
Expand description

A 32-bit signed integer with a restricted range.

This type holds an i32 value such that LOWER <= value <= UPPER

Limitations

If you try to instantiate this type with LOWER > UPPER, you will get an uninhabitable type. It would be better if we could check that at compile time, and prevent such types from being named.

Implementations

Lower bound

Upper bound

Return the underlying i32 value.

This value will always be between Self::LOWER and Self::UPPER, inclusive.

If val is within range, return a new BoundedInt32 wrapping it; otherwise, clamp it to the upper or lower bound as appropriate.

If val is an acceptable value inside the range for this type, return a new BoundedInt32. Otherwise return an error.

Convert from the underlying type, clamping to the upper or lower bound if needed.

Panics

This function will panic if UPPER < LOWER.

Convert from a string, clamping to the upper or lower bound if needed.

Limitations

If the input is a number that cannot be represented as an i32, then we return an error instead of clamping it.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.