Trait malachite_base::num::conversion::traits::SaturatingFrom
source · [−]pub trait SaturatingFrom<T>: Sized {
fn saturating_from(value: T) -> Self;
}
Expand description
Converts a value from one type to another, where if the conversion is not exact the result is set to the maximum or minimum value of the result type, whichever is closer.
Required Methods
fn saturating_from(value: T) -> Self
Implementations on Foreign Types
sourceimpl SaturatingFrom<u8> for u8
impl SaturatingFrom<u8> for u8
sourcefn saturating_from(value: u8) -> u8
fn saturating_from(value: u8) -> u8
Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u16> for u16
impl SaturatingFrom<u16> for u16
sourcefn saturating_from(value: u16) -> u16
fn saturating_from(value: u16) -> u16
Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u32> for u32
impl SaturatingFrom<u32> for u32
sourcefn saturating_from(value: u32) -> u32
fn saturating_from(value: u32) -> u32
Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u64> for u64
impl SaturatingFrom<u64> for u64
sourcefn saturating_from(value: u64) -> u64
fn saturating_from(value: u64) -> u64
Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u128> for u128
impl SaturatingFrom<u128> for u128
sourcefn saturating_from(value: u128) -> u128
fn saturating_from(value: u128) -> u128
Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<usize> for usize
impl SaturatingFrom<usize> for usize
sourcefn saturating_from(value: usize) -> usize
fn saturating_from(value: usize) -> usize
Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i8> for i8
impl SaturatingFrom<i8> for i8
sourcefn saturating_from(value: i8) -> i8
fn saturating_from(value: i8) -> i8
Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i16> for i16
impl SaturatingFrom<i16> for i16
sourcefn saturating_from(value: i16) -> i16
fn saturating_from(value: i16) -> i16
Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i32> for i32
impl SaturatingFrom<i32> for i32
sourcefn saturating_from(value: i32) -> i32
fn saturating_from(value: i32) -> i32
Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i64> for i64
impl SaturatingFrom<i64> for i64
sourcefn saturating_from(value: i64) -> i64
fn saturating_from(value: i64) -> i64
Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i128> for i128
impl SaturatingFrom<i128> for i128
sourcefn saturating_from(value: i128) -> i128
fn saturating_from(value: i128) -> i128
Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<isize> for isize
impl SaturatingFrom<isize> for isize
sourcefn saturating_from(value: isize) -> isize
fn saturating_from(value: isize) -> isize
Converts a value to its own type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u8> for u16
impl SaturatingFrom<u8> for u16
sourcefn saturating_from(value: u8) -> u16
fn saturating_from(value: u8) -> u16
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u16> for u8
impl SaturatingFrom<u16> for u8
sourcefn saturating_from(value: u16) -> u8
fn saturating_from(value: u16) -> u8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u8> for u32
impl SaturatingFrom<u8> for u32
sourcefn saturating_from(value: u8) -> u32
fn saturating_from(value: u8) -> u32
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u32> for u8
impl SaturatingFrom<u32> for u8
sourcefn saturating_from(value: u32) -> u8
fn saturating_from(value: u32) -> u8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u8> for u64
impl SaturatingFrom<u8> for u64
sourcefn saturating_from(value: u8) -> u64
fn saturating_from(value: u8) -> u64
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u64> for u8
impl SaturatingFrom<u64> for u8
sourcefn saturating_from(value: u64) -> u8
fn saturating_from(value: u64) -> u8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u8> for u128
impl SaturatingFrom<u8> for u128
sourcefn saturating_from(value: u8) -> u128
fn saturating_from(value: u8) -> u128
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u128> for u8
impl SaturatingFrom<u128> for u8
sourcefn saturating_from(value: u128) -> u8
fn saturating_from(value: u128) -> u8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u8> for usize
impl SaturatingFrom<u8> for usize
sourcefn saturating_from(value: u8) -> usize
fn saturating_from(value: u8) -> usize
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<usize> for u8
impl SaturatingFrom<usize> for u8
sourcefn saturating_from(value: usize) -> u8
fn saturating_from(value: usize) -> u8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u8> for i16
impl SaturatingFrom<u8> for i16
sourcefn saturating_from(value: u8) -> i16
fn saturating_from(value: u8) -> i16
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i16> for u8
impl SaturatingFrom<i16> for u8
sourcefn saturating_from(value: i16) -> u8
fn saturating_from(value: i16) -> u8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u8> for i32
impl SaturatingFrom<u8> for i32
sourcefn saturating_from(value: u8) -> i32
fn saturating_from(value: u8) -> i32
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i32> for u8
impl SaturatingFrom<i32> for u8
sourcefn saturating_from(value: i32) -> u8
fn saturating_from(value: i32) -> u8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u8> for i64
impl SaturatingFrom<u8> for i64
sourcefn saturating_from(value: u8) -> i64
fn saturating_from(value: u8) -> i64
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i64> for u8
impl SaturatingFrom<i64> for u8
sourcefn saturating_from(value: i64) -> u8
fn saturating_from(value: i64) -> u8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u8> for i128
impl SaturatingFrom<u8> for i128
sourcefn saturating_from(value: u8) -> i128
fn saturating_from(value: u8) -> i128
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i128> for u8
impl SaturatingFrom<i128> for u8
sourcefn saturating_from(value: i128) -> u8
fn saturating_from(value: i128) -> u8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u8> for isize
impl SaturatingFrom<u8> for isize
sourcefn saturating_from(value: u8) -> isize
fn saturating_from(value: u8) -> isize
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<isize> for u8
impl SaturatingFrom<isize> for u8
sourcefn saturating_from(value: isize) -> u8
fn saturating_from(value: isize) -> u8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u16> for u32
impl SaturatingFrom<u16> for u32
sourcefn saturating_from(value: u16) -> u32
fn saturating_from(value: u16) -> u32
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u32> for u16
impl SaturatingFrom<u32> for u16
sourcefn saturating_from(value: u32) -> u16
fn saturating_from(value: u32) -> u16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u16> for u64
impl SaturatingFrom<u16> for u64
sourcefn saturating_from(value: u16) -> u64
fn saturating_from(value: u16) -> u64
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u64> for u16
impl SaturatingFrom<u64> for u16
sourcefn saturating_from(value: u64) -> u16
fn saturating_from(value: u64) -> u16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u16> for u128
impl SaturatingFrom<u16> for u128
sourcefn saturating_from(value: u16) -> u128
fn saturating_from(value: u16) -> u128
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u128> for u16
impl SaturatingFrom<u128> for u16
sourcefn saturating_from(value: u128) -> u16
fn saturating_from(value: u128) -> u16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u16> for usize
impl SaturatingFrom<u16> for usize
sourcefn saturating_from(value: u16) -> usize
fn saturating_from(value: u16) -> usize
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<usize> for u16
impl SaturatingFrom<usize> for u16
sourcefn saturating_from(value: usize) -> u16
fn saturating_from(value: usize) -> u16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u16> for i32
impl SaturatingFrom<u16> for i32
sourcefn saturating_from(value: u16) -> i32
fn saturating_from(value: u16) -> i32
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i32> for u16
impl SaturatingFrom<i32> for u16
sourcefn saturating_from(value: i32) -> u16
fn saturating_from(value: i32) -> u16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u16> for i64
impl SaturatingFrom<u16> for i64
sourcefn saturating_from(value: u16) -> i64
fn saturating_from(value: u16) -> i64
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i64> for u16
impl SaturatingFrom<i64> for u16
sourcefn saturating_from(value: i64) -> u16
fn saturating_from(value: i64) -> u16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u16> for i128
impl SaturatingFrom<u16> for i128
sourcefn saturating_from(value: u16) -> i128
fn saturating_from(value: u16) -> i128
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i128> for u16
impl SaturatingFrom<i128> for u16
sourcefn saturating_from(value: i128) -> u16
fn saturating_from(value: i128) -> u16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u32> for u64
impl SaturatingFrom<u32> for u64
sourcefn saturating_from(value: u32) -> u64
fn saturating_from(value: u32) -> u64
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u64> for u32
impl SaturatingFrom<u64> for u32
sourcefn saturating_from(value: u64) -> u32
fn saturating_from(value: u64) -> u32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u32> for u128
impl SaturatingFrom<u32> for u128
sourcefn saturating_from(value: u32) -> u128
fn saturating_from(value: u32) -> u128
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u128> for u32
impl SaturatingFrom<u128> for u32
sourcefn saturating_from(value: u128) -> u32
fn saturating_from(value: u128) -> u32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u32> for i64
impl SaturatingFrom<u32> for i64
sourcefn saturating_from(value: u32) -> i64
fn saturating_from(value: u32) -> i64
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i64> for u32
impl SaturatingFrom<i64> for u32
sourcefn saturating_from(value: i64) -> u32
fn saturating_from(value: i64) -> u32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u32> for i128
impl SaturatingFrom<u32> for i128
sourcefn saturating_from(value: u32) -> i128
fn saturating_from(value: u32) -> i128
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i128> for u32
impl SaturatingFrom<i128> for u32
sourcefn saturating_from(value: i128) -> u32
fn saturating_from(value: i128) -> u32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u64> for u128
impl SaturatingFrom<u64> for u128
sourcefn saturating_from(value: u64) -> u128
fn saturating_from(value: u64) -> u128
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u128> for u64
impl SaturatingFrom<u128> for u64
sourcefn saturating_from(value: u128) -> u64
fn saturating_from(value: u128) -> u64
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u64> for i128
impl SaturatingFrom<u64> for i128
sourcefn saturating_from(value: u64) -> i128
fn saturating_from(value: u64) -> i128
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i128> for u64
impl SaturatingFrom<i128> for u64
sourcefn saturating_from(value: i128) -> u64
fn saturating_from(value: i128) -> u64
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i8> for i16
impl SaturatingFrom<i8> for i16
sourcefn saturating_from(value: i8) -> i16
fn saturating_from(value: i8) -> i16
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i16> for i8
impl SaturatingFrom<i16> for i8
sourcefn saturating_from(value: i16) -> i8
fn saturating_from(value: i16) -> i8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i8> for i32
impl SaturatingFrom<i8> for i32
sourcefn saturating_from(value: i8) -> i32
fn saturating_from(value: i8) -> i32
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i32> for i8
impl SaturatingFrom<i32> for i8
sourcefn saturating_from(value: i32) -> i8
fn saturating_from(value: i32) -> i8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i8> for i64
impl SaturatingFrom<i8> for i64
sourcefn saturating_from(value: i8) -> i64
fn saturating_from(value: i8) -> i64
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i64> for i8
impl SaturatingFrom<i64> for i8
sourcefn saturating_from(value: i64) -> i8
fn saturating_from(value: i64) -> i8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i8> for i128
impl SaturatingFrom<i8> for i128
sourcefn saturating_from(value: i8) -> i128
fn saturating_from(value: i8) -> i128
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i128> for i8
impl SaturatingFrom<i128> for i8
sourcefn saturating_from(value: i128) -> i8
fn saturating_from(value: i128) -> i8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i8> for isize
impl SaturatingFrom<i8> for isize
sourcefn saturating_from(value: i8) -> isize
fn saturating_from(value: i8) -> isize
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<isize> for i8
impl SaturatingFrom<isize> for i8
sourcefn saturating_from(value: isize) -> i8
fn saturating_from(value: isize) -> i8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i16> for i32
impl SaturatingFrom<i16> for i32
sourcefn saturating_from(value: i16) -> i32
fn saturating_from(value: i16) -> i32
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i32> for i16
impl SaturatingFrom<i32> for i16
sourcefn saturating_from(value: i32) -> i16
fn saturating_from(value: i32) -> i16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i16> for i64
impl SaturatingFrom<i16> for i64
sourcefn saturating_from(value: i16) -> i64
fn saturating_from(value: i16) -> i64
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i64> for i16
impl SaturatingFrom<i64> for i16
sourcefn saturating_from(value: i64) -> i16
fn saturating_from(value: i64) -> i16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i16> for i128
impl SaturatingFrom<i16> for i128
sourcefn saturating_from(value: i16) -> i128
fn saturating_from(value: i16) -> i128
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i128> for i16
impl SaturatingFrom<i128> for i16
sourcefn saturating_from(value: i128) -> i16
fn saturating_from(value: i128) -> i16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i16> for isize
impl SaturatingFrom<i16> for isize
sourcefn saturating_from(value: i16) -> isize
fn saturating_from(value: i16) -> isize
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<isize> for i16
impl SaturatingFrom<isize> for i16
sourcefn saturating_from(value: isize) -> i16
fn saturating_from(value: isize) -> i16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i32> for i64
impl SaturatingFrom<i32> for i64
sourcefn saturating_from(value: i32) -> i64
fn saturating_from(value: i32) -> i64
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i64> for i32
impl SaturatingFrom<i64> for i32
sourcefn saturating_from(value: i64) -> i32
fn saturating_from(value: i64) -> i32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i32> for i128
impl SaturatingFrom<i32> for i128
sourcefn saturating_from(value: i32) -> i128
fn saturating_from(value: i32) -> i128
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i128> for i32
impl SaturatingFrom<i128> for i32
sourcefn saturating_from(value: i128) -> i32
fn saturating_from(value: i128) -> i32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i64> for i128
impl SaturatingFrom<i64> for i128
sourcefn saturating_from(value: i64) -> i128
fn saturating_from(value: i64) -> i128
Converts a value to another type. This conversion is always valid and always leaves the value unchanged.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i128> for i64
impl SaturatingFrom<i128> for i64
sourcefn saturating_from(value: i128) -> i64
fn saturating_from(value: i128) -> i64
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u8> for i8
impl SaturatingFrom<u8> for i8
sourcefn saturating_from(value: u8) -> i8
fn saturating_from(value: u8) -> i8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i8> for u8
impl SaturatingFrom<i8> for u8
sourcefn saturating_from(value: i8) -> u8
fn saturating_from(value: i8) -> u8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u16> for i8
impl SaturatingFrom<u16> for i8
sourcefn saturating_from(value: u16) -> i8
fn saturating_from(value: u16) -> i8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i8> for u16
impl SaturatingFrom<i8> for u16
sourcefn saturating_from(value: i8) -> u16
fn saturating_from(value: i8) -> u16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u16> for i16
impl SaturatingFrom<u16> for i16
sourcefn saturating_from(value: u16) -> i16
fn saturating_from(value: u16) -> i16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i16> for u16
impl SaturatingFrom<i16> for u16
sourcefn saturating_from(value: i16) -> u16
fn saturating_from(value: i16) -> u16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u16> for isize
impl SaturatingFrom<u16> for isize
sourcefn saturating_from(value: u16) -> isize
fn saturating_from(value: u16) -> isize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<isize> for u16
impl SaturatingFrom<isize> for u16
sourcefn saturating_from(value: isize) -> u16
fn saturating_from(value: isize) -> u16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u32> for usize
impl SaturatingFrom<u32> for usize
sourcefn saturating_from(value: u32) -> usize
fn saturating_from(value: u32) -> usize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<usize> for u32
impl SaturatingFrom<usize> for u32
sourcefn saturating_from(value: usize) -> u32
fn saturating_from(value: usize) -> u32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u32> for i8
impl SaturatingFrom<u32> for i8
sourcefn saturating_from(value: u32) -> i8
fn saturating_from(value: u32) -> i8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i8> for u32
impl SaturatingFrom<i8> for u32
sourcefn saturating_from(value: i8) -> u32
fn saturating_from(value: i8) -> u32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u32> for i16
impl SaturatingFrom<u32> for i16
sourcefn saturating_from(value: u32) -> i16
fn saturating_from(value: u32) -> i16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i16> for u32
impl SaturatingFrom<i16> for u32
sourcefn saturating_from(value: i16) -> u32
fn saturating_from(value: i16) -> u32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u32> for i32
impl SaturatingFrom<u32> for i32
sourcefn saturating_from(value: u32) -> i32
fn saturating_from(value: u32) -> i32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i32> for u32
impl SaturatingFrom<i32> for u32
sourcefn saturating_from(value: i32) -> u32
fn saturating_from(value: i32) -> u32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u32> for isize
impl SaturatingFrom<u32> for isize
sourcefn saturating_from(value: u32) -> isize
fn saturating_from(value: u32) -> isize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<isize> for u32
impl SaturatingFrom<isize> for u32
sourcefn saturating_from(value: isize) -> u32
fn saturating_from(value: isize) -> u32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u64> for usize
impl SaturatingFrom<u64> for usize
sourcefn saturating_from(value: u64) -> usize
fn saturating_from(value: u64) -> usize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<usize> for u64
impl SaturatingFrom<usize> for u64
sourcefn saturating_from(value: usize) -> u64
fn saturating_from(value: usize) -> u64
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u64> for i8
impl SaturatingFrom<u64> for i8
sourcefn saturating_from(value: u64) -> i8
fn saturating_from(value: u64) -> i8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i8> for u64
impl SaturatingFrom<i8> for u64
sourcefn saturating_from(value: i8) -> u64
fn saturating_from(value: i8) -> u64
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u64> for i16
impl SaturatingFrom<u64> for i16
sourcefn saturating_from(value: u64) -> i16
fn saturating_from(value: u64) -> i16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i16> for u64
impl SaturatingFrom<i16> for u64
sourcefn saturating_from(value: i16) -> u64
fn saturating_from(value: i16) -> u64
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u64> for i32
impl SaturatingFrom<u64> for i32
sourcefn saturating_from(value: u64) -> i32
fn saturating_from(value: u64) -> i32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i32> for u64
impl SaturatingFrom<i32> for u64
sourcefn saturating_from(value: i32) -> u64
fn saturating_from(value: i32) -> u64
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u64> for i64
impl SaturatingFrom<u64> for i64
sourcefn saturating_from(value: u64) -> i64
fn saturating_from(value: u64) -> i64
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i64> for u64
impl SaturatingFrom<i64> for u64
sourcefn saturating_from(value: i64) -> u64
fn saturating_from(value: i64) -> u64
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u64> for isize
impl SaturatingFrom<u64> for isize
sourcefn saturating_from(value: u64) -> isize
fn saturating_from(value: u64) -> isize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<isize> for u64
impl SaturatingFrom<isize> for u64
sourcefn saturating_from(value: isize) -> u64
fn saturating_from(value: isize) -> u64
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u128> for usize
impl SaturatingFrom<u128> for usize
sourcefn saturating_from(value: u128) -> usize
fn saturating_from(value: u128) -> usize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<usize> for u128
impl SaturatingFrom<usize> for u128
sourcefn saturating_from(value: usize) -> u128
fn saturating_from(value: usize) -> u128
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u128> for i8
impl SaturatingFrom<u128> for i8
sourcefn saturating_from(value: u128) -> i8
fn saturating_from(value: u128) -> i8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i8> for u128
impl SaturatingFrom<i8> for u128
sourcefn saturating_from(value: i8) -> u128
fn saturating_from(value: i8) -> u128
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u128> for i16
impl SaturatingFrom<u128> for i16
sourcefn saturating_from(value: u128) -> i16
fn saturating_from(value: u128) -> i16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i16> for u128
impl SaturatingFrom<i16> for u128
sourcefn saturating_from(value: i16) -> u128
fn saturating_from(value: i16) -> u128
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u128> for i32
impl SaturatingFrom<u128> for i32
sourcefn saturating_from(value: u128) -> i32
fn saturating_from(value: u128) -> i32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i32> for u128
impl SaturatingFrom<i32> for u128
sourcefn saturating_from(value: i32) -> u128
fn saturating_from(value: i32) -> u128
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u128> for i64
impl SaturatingFrom<u128> for i64
sourcefn saturating_from(value: u128) -> i64
fn saturating_from(value: u128) -> i64
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i64> for u128
impl SaturatingFrom<i64> for u128
sourcefn saturating_from(value: i64) -> u128
fn saturating_from(value: i64) -> u128
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u128> for i128
impl SaturatingFrom<u128> for i128
sourcefn saturating_from(value: u128) -> i128
fn saturating_from(value: u128) -> i128
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i128> for u128
impl SaturatingFrom<i128> for u128
sourcefn saturating_from(value: i128) -> u128
fn saturating_from(value: i128) -> u128
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<u128> for isize
impl SaturatingFrom<u128> for isize
sourcefn saturating_from(value: u128) -> isize
fn saturating_from(value: u128) -> isize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<isize> for u128
impl SaturatingFrom<isize> for u128
sourcefn saturating_from(value: isize) -> u128
fn saturating_from(value: isize) -> u128
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<usize> for i8
impl SaturatingFrom<usize> for i8
sourcefn saturating_from(value: usize) -> i8
fn saturating_from(value: usize) -> i8
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i8> for usize
impl SaturatingFrom<i8> for usize
sourcefn saturating_from(value: i8) -> usize
fn saturating_from(value: i8) -> usize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<usize> for i16
impl SaturatingFrom<usize> for i16
sourcefn saturating_from(value: usize) -> i16
fn saturating_from(value: usize) -> i16
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i16> for usize
impl SaturatingFrom<i16> for usize
sourcefn saturating_from(value: i16) -> usize
fn saturating_from(value: i16) -> usize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<usize> for i32
impl SaturatingFrom<usize> for i32
sourcefn saturating_from(value: usize) -> i32
fn saturating_from(value: usize) -> i32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i32> for usize
impl SaturatingFrom<i32> for usize
sourcefn saturating_from(value: i32) -> usize
fn saturating_from(value: i32) -> usize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<usize> for i64
impl SaturatingFrom<usize> for i64
sourcefn saturating_from(value: usize) -> i64
fn saturating_from(value: usize) -> i64
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i64> for usize
impl SaturatingFrom<i64> for usize
sourcefn saturating_from(value: i64) -> usize
fn saturating_from(value: i64) -> usize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<usize> for i128
impl SaturatingFrom<usize> for i128
sourcefn saturating_from(value: usize) -> i128
fn saturating_from(value: usize) -> i128
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i128> for usize
impl SaturatingFrom<i128> for usize
sourcefn saturating_from(value: i128) -> usize
fn saturating_from(value: i128) -> usize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<usize> for isize
impl SaturatingFrom<usize> for isize
sourcefn saturating_from(value: usize) -> isize
fn saturating_from(value: usize) -> isize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<isize> for usize
impl SaturatingFrom<isize> for usize
sourcefn saturating_from(value: isize) -> usize
fn saturating_from(value: isize) -> usize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i32> for isize
impl SaturatingFrom<i32> for isize
sourcefn saturating_from(value: i32) -> isize
fn saturating_from(value: i32) -> isize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<isize> for i32
impl SaturatingFrom<isize> for i32
sourcefn saturating_from(value: isize) -> i32
fn saturating_from(value: isize) -> i32
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i64> for isize
impl SaturatingFrom<i64> for isize
sourcefn saturating_from(value: i64) -> isize
fn saturating_from(value: i64) -> isize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<isize> for i64
impl SaturatingFrom<isize> for i64
sourcefn saturating_from(value: isize) -> i64
fn saturating_from(value: isize) -> i64
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<i128> for isize
impl SaturatingFrom<i128> for isize
sourcefn saturating_from(value: i128) -> isize
fn saturating_from(value: i128) -> isize
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl SaturatingFrom<isize> for i128
impl SaturatingFrom<isize> for i128
sourcefn saturating_from(value: isize) -> i128
fn saturating_from(value: isize) -> i128
Converts a value to another type. If the value cannot be represented in the new type, the maximum or minimum value of the new type, whichever is closer, is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} 0 & n < 0 \\ 2^W-1 & \text{if} \quad n \geq 2^W, \\ n & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} -2^{W-1} & \text{if} \quad n < -2^{W-1}, \\ 2^{W-1}-1 & \text{if} \quad n \geq 2^{W-1}, \\ n & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.