Trait malachite_base::num::conversion::traits::SaturatingFrom
source · pub trait SaturatingFrom<T>: Sized {
// Required method
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
Object Safety§
Implementations on Foreign Types§
source§impl SaturatingFrom<i8> for i8
impl SaturatingFrom<i8> for i8
source§impl SaturatingFrom<i8> for i16
impl SaturatingFrom<i8> for i16
source§impl SaturatingFrom<i8> for i32
impl SaturatingFrom<i8> for i32
source§impl SaturatingFrom<i8> for i64
impl SaturatingFrom<i8> for i64
source§impl SaturatingFrom<i8> for i128
impl SaturatingFrom<i8> for i128
source§impl SaturatingFrom<i8> for isize
impl SaturatingFrom<i8> for isize
source§impl SaturatingFrom<i8> for u8
impl SaturatingFrom<i8> for u8
source§fn 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.
source§impl SaturatingFrom<i8> for u16
impl SaturatingFrom<i8> for u16
source§fn 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.
source§impl SaturatingFrom<i8> for u32
impl SaturatingFrom<i8> for u32
source§fn 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.
source§impl SaturatingFrom<i8> for u64
impl SaturatingFrom<i8> for u64
source§fn 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.
source§impl SaturatingFrom<i8> for u128
impl SaturatingFrom<i8> for u128
source§fn 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.
source§impl SaturatingFrom<i8> for usize
impl SaturatingFrom<i8> for usize
source§fn 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.
source§impl SaturatingFrom<i16> for i8
impl SaturatingFrom<i16> for i8
source§fn 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.
source§impl SaturatingFrom<i16> for i16
impl SaturatingFrom<i16> for i16
source§impl SaturatingFrom<i16> for i32
impl SaturatingFrom<i16> for i32
source§impl SaturatingFrom<i16> for i64
impl SaturatingFrom<i16> for i64
source§impl SaturatingFrom<i16> for i128
impl SaturatingFrom<i16> for i128
source§impl SaturatingFrom<i16> for isize
impl SaturatingFrom<i16> for isize
source§impl SaturatingFrom<i16> for u8
impl SaturatingFrom<i16> for u8
source§fn 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.
source§impl SaturatingFrom<i16> for u16
impl SaturatingFrom<i16> for u16
source§fn 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.
source§impl SaturatingFrom<i16> for u32
impl SaturatingFrom<i16> for u32
source§fn 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.
source§impl SaturatingFrom<i16> for u64
impl SaturatingFrom<i16> for u64
source§fn 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.
source§impl SaturatingFrom<i16> for u128
impl SaturatingFrom<i16> for u128
source§fn 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.
source§impl SaturatingFrom<i16> for usize
impl SaturatingFrom<i16> for usize
source§fn 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.
source§impl SaturatingFrom<i32> for i8
impl SaturatingFrom<i32> for i8
source§fn 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.
source§impl SaturatingFrom<i32> for i16
impl SaturatingFrom<i32> for i16
source§fn 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.
source§impl SaturatingFrom<i32> for i32
impl SaturatingFrom<i32> for i32
source§impl SaturatingFrom<i32> for i64
impl SaturatingFrom<i32> for i64
source§impl SaturatingFrom<i32> for i128
impl SaturatingFrom<i32> for i128
source§impl SaturatingFrom<i32> for isize
impl SaturatingFrom<i32> for isize
source§fn 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.
source§impl SaturatingFrom<i32> for u8
impl SaturatingFrom<i32> for u8
source§fn 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.
source§impl SaturatingFrom<i32> for u16
impl SaturatingFrom<i32> for u16
source§fn 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.
source§impl SaturatingFrom<i32> for u32
impl SaturatingFrom<i32> for u32
source§fn 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.
source§impl SaturatingFrom<i32> for u64
impl SaturatingFrom<i32> for u64
source§fn 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.
source§impl SaturatingFrom<i32> for u128
impl SaturatingFrom<i32> for u128
source§fn 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.
source§impl SaturatingFrom<i32> for usize
impl SaturatingFrom<i32> for usize
source§fn 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.
source§impl SaturatingFrom<i64> for i8
impl SaturatingFrom<i64> for i8
source§fn 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.
source§impl SaturatingFrom<i64> for i16
impl SaturatingFrom<i64> for i16
source§fn 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.
source§impl SaturatingFrom<i64> for i32
impl SaturatingFrom<i64> for i32
source§fn 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.
source§impl SaturatingFrom<i64> for i64
impl SaturatingFrom<i64> for i64
source§impl SaturatingFrom<i64> for i128
impl SaturatingFrom<i64> for i128
source§impl SaturatingFrom<i64> for isize
impl SaturatingFrom<i64> for isize
source§fn 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.
source§impl SaturatingFrom<i64> for u8
impl SaturatingFrom<i64> for u8
source§fn 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.
source§impl SaturatingFrom<i64> for u16
impl SaturatingFrom<i64> for u16
source§fn 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.
source§impl SaturatingFrom<i64> for u32
impl SaturatingFrom<i64> for u32
source§fn 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.
source§impl SaturatingFrom<i64> for u64
impl SaturatingFrom<i64> for u64
source§fn 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.
source§impl SaturatingFrom<i64> for u128
impl SaturatingFrom<i64> for u128
source§fn 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.
source§impl SaturatingFrom<i64> for usize
impl SaturatingFrom<i64> for usize
source§fn 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.
source§impl SaturatingFrom<i128> for i8
impl SaturatingFrom<i128> for i8
source§fn 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.
source§impl SaturatingFrom<i128> for i16
impl SaturatingFrom<i128> for i16
source§fn 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.
source§impl SaturatingFrom<i128> for i32
impl SaturatingFrom<i128> for i32
source§fn 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.
source§impl SaturatingFrom<i128> for i64
impl SaturatingFrom<i128> for i64
source§fn 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.
source§impl SaturatingFrom<i128> for i128
impl SaturatingFrom<i128> for i128
source§impl SaturatingFrom<i128> for isize
impl SaturatingFrom<i128> for isize
source§fn 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.
source§impl SaturatingFrom<i128> for u8
impl SaturatingFrom<i128> for u8
source§fn 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.
source§impl SaturatingFrom<i128> for u16
impl SaturatingFrom<i128> for u16
source§fn 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.
source§impl SaturatingFrom<i128> for u32
impl SaturatingFrom<i128> for u32
source§fn 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.
source§impl SaturatingFrom<i128> for u64
impl SaturatingFrom<i128> for u64
source§fn 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.
source§impl SaturatingFrom<i128> for u128
impl SaturatingFrom<i128> for u128
source§fn 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.
source§impl SaturatingFrom<i128> for usize
impl SaturatingFrom<i128> for usize
source§fn 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.
source§impl SaturatingFrom<isize> for i8
impl SaturatingFrom<isize> for i8
source§fn 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.
source§impl SaturatingFrom<isize> for i16
impl SaturatingFrom<isize> for i16
source§fn 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.
source§impl SaturatingFrom<isize> for i32
impl SaturatingFrom<isize> for i32
source§fn 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.
source§impl SaturatingFrom<isize> for i64
impl SaturatingFrom<isize> for i64
source§fn 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.
source§impl SaturatingFrom<isize> for i128
impl SaturatingFrom<isize> for i128
source§fn 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.
source§impl SaturatingFrom<isize> for isize
impl SaturatingFrom<isize> for isize
source§impl SaturatingFrom<isize> for u8
impl SaturatingFrom<isize> for u8
source§fn 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.
source§impl SaturatingFrom<isize> for u16
impl SaturatingFrom<isize> for u16
source§fn 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.
source§impl SaturatingFrom<isize> for u32
impl SaturatingFrom<isize> for u32
source§fn 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.
source§impl SaturatingFrom<isize> for u64
impl SaturatingFrom<isize> for u64
source§fn 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.
source§impl SaturatingFrom<isize> for u128
impl SaturatingFrom<isize> for u128
source§fn 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.
source§impl SaturatingFrom<isize> for usize
impl SaturatingFrom<isize> for usize
source§fn 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.
source§impl SaturatingFrom<u8> for i8
impl SaturatingFrom<u8> for i8
source§fn 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.
source§impl SaturatingFrom<u8> for i16
impl SaturatingFrom<u8> for i16
source§impl SaturatingFrom<u8> for i32
impl SaturatingFrom<u8> for i32
source§impl SaturatingFrom<u8> for i64
impl SaturatingFrom<u8> for i64
source§impl SaturatingFrom<u8> for i128
impl SaturatingFrom<u8> for i128
source§impl SaturatingFrom<u8> for isize
impl SaturatingFrom<u8> for isize
source§impl SaturatingFrom<u8> for u8
impl SaturatingFrom<u8> for u8
source§impl SaturatingFrom<u8> for u16
impl SaturatingFrom<u8> for u16
source§impl SaturatingFrom<u8> for u32
impl SaturatingFrom<u8> for u32
source§impl SaturatingFrom<u8> for u64
impl SaturatingFrom<u8> for u64
source§impl SaturatingFrom<u8> for u128
impl SaturatingFrom<u8> for u128
source§impl SaturatingFrom<u8> for usize
impl SaturatingFrom<u8> for usize
source§impl SaturatingFrom<u16> for i8
impl SaturatingFrom<u16> for i8
source§fn 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.
source§impl SaturatingFrom<u16> for i16
impl SaturatingFrom<u16> for i16
source§fn 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.
source§impl SaturatingFrom<u16> for i32
impl SaturatingFrom<u16> for i32
source§impl SaturatingFrom<u16> for i64
impl SaturatingFrom<u16> for i64
source§impl SaturatingFrom<u16> for i128
impl SaturatingFrom<u16> for i128
source§impl SaturatingFrom<u16> for isize
impl SaturatingFrom<u16> for isize
source§fn 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.
source§impl SaturatingFrom<u16> for u8
impl SaturatingFrom<u16> for u8
source§fn 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.
source§impl SaturatingFrom<u16> for u16
impl SaturatingFrom<u16> for u16
source§impl SaturatingFrom<u16> for u32
impl SaturatingFrom<u16> for u32
source§impl SaturatingFrom<u16> for u64
impl SaturatingFrom<u16> for u64
source§impl SaturatingFrom<u16> for u128
impl SaturatingFrom<u16> for u128
source§impl SaturatingFrom<u16> for usize
impl SaturatingFrom<u16> for usize
source§impl SaturatingFrom<u32> for i8
impl SaturatingFrom<u32> for i8
source§fn 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.
source§impl SaturatingFrom<u32> for i16
impl SaturatingFrom<u32> for i16
source§fn 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.
source§impl SaturatingFrom<u32> for i32
impl SaturatingFrom<u32> for i32
source§fn 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.
source§impl SaturatingFrom<u32> for i64
impl SaturatingFrom<u32> for i64
source§impl SaturatingFrom<u32> for i128
impl SaturatingFrom<u32> for i128
source§impl SaturatingFrom<u32> for isize
impl SaturatingFrom<u32> for isize
source§fn 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.
source§impl SaturatingFrom<u32> for u8
impl SaturatingFrom<u32> for u8
source§fn 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.
source§impl SaturatingFrom<u32> for u16
impl SaturatingFrom<u32> for u16
source§fn 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.
source§impl SaturatingFrom<u32> for u32
impl SaturatingFrom<u32> for u32
source§impl SaturatingFrom<u32> for u64
impl SaturatingFrom<u32> for u64
source§impl SaturatingFrom<u32> for u128
impl SaturatingFrom<u32> for u128
source§impl SaturatingFrom<u32> for usize
impl SaturatingFrom<u32> for usize
source§fn 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.
source§impl SaturatingFrom<u64> for i8
impl SaturatingFrom<u64> for i8
source§fn 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.
source§impl SaturatingFrom<u64> for i16
impl SaturatingFrom<u64> for i16
source§fn 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.
source§impl SaturatingFrom<u64> for i32
impl SaturatingFrom<u64> for i32
source§fn 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.
source§impl SaturatingFrom<u64> for i64
impl SaturatingFrom<u64> for i64
source§fn 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.
source§impl SaturatingFrom<u64> for i128
impl SaturatingFrom<u64> for i128
source§impl SaturatingFrom<u64> for isize
impl SaturatingFrom<u64> for isize
source§fn 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.
source§impl SaturatingFrom<u64> for u8
impl SaturatingFrom<u64> for u8
source§fn 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.
source§impl SaturatingFrom<u64> for u16
impl SaturatingFrom<u64> for u16
source§fn 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.
source§impl SaturatingFrom<u64> for u32
impl SaturatingFrom<u64> for u32
source§fn 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.
source§impl SaturatingFrom<u64> for u64
impl SaturatingFrom<u64> for u64
source§impl SaturatingFrom<u64> for u128
impl SaturatingFrom<u64> for u128
source§impl SaturatingFrom<u64> for usize
impl SaturatingFrom<u64> for usize
source§fn 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.
source§impl SaturatingFrom<u128> for i8
impl SaturatingFrom<u128> for i8
source§fn 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.
source§impl SaturatingFrom<u128> for i16
impl SaturatingFrom<u128> for i16
source§fn 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.
source§impl SaturatingFrom<u128> for i32
impl SaturatingFrom<u128> for i32
source§fn 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.
source§impl SaturatingFrom<u128> for i64
impl SaturatingFrom<u128> for i64
source§fn 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.
source§impl SaturatingFrom<u128> for i128
impl SaturatingFrom<u128> for i128
source§fn 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.
source§impl SaturatingFrom<u128> for isize
impl SaturatingFrom<u128> for isize
source§fn 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.
source§impl SaturatingFrom<u128> for u8
impl SaturatingFrom<u128> for u8
source§fn 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.
source§impl SaturatingFrom<u128> for u16
impl SaturatingFrom<u128> for u16
source§fn 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.
source§impl SaturatingFrom<u128> for u32
impl SaturatingFrom<u128> for u32
source§fn 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.
source§impl SaturatingFrom<u128> for u64
impl SaturatingFrom<u128> for u64
source§fn 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.
source§impl SaturatingFrom<u128> for u128
impl SaturatingFrom<u128> for u128
source§impl SaturatingFrom<u128> for usize
impl SaturatingFrom<u128> for usize
source§fn 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.
source§impl SaturatingFrom<usize> for i8
impl SaturatingFrom<usize> for i8
source§fn 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.
source§impl SaturatingFrom<usize> for i16
impl SaturatingFrom<usize> for i16
source§fn 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.
source§impl SaturatingFrom<usize> for i32
impl SaturatingFrom<usize> for i32
source§fn 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.
source§impl SaturatingFrom<usize> for i64
impl SaturatingFrom<usize> for i64
source§fn 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.
source§impl SaturatingFrom<usize> for i128
impl SaturatingFrom<usize> for i128
source§fn 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.
source§impl SaturatingFrom<usize> for isize
impl SaturatingFrom<usize> for isize
source§fn 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.
source§impl SaturatingFrom<usize> for u8
impl SaturatingFrom<usize> for u8
source§fn 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.
source§impl SaturatingFrom<usize> for u16
impl SaturatingFrom<usize> for u16
source§fn 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.
source§impl SaturatingFrom<usize> for u32
impl SaturatingFrom<usize> for u32
source§fn 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.
source§impl SaturatingFrom<usize> for u64
impl SaturatingFrom<usize> for u64
source§fn 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.
source§impl SaturatingFrom<usize> for u128
impl SaturatingFrom<usize> for u128
source§fn 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.