Trait malachite_base::num::conversion::traits::CheckedFrom
source · [−]pub trait CheckedFrom<T>: Sized {
fn checked_from(value: T) -> Option<Self>;
}
Expand description
Converts a value from one type to another. If the conversion fails, None
is returned.
If CheckedFrom
is implemented, it usually makes sense to implement ConvertibleFrom
as
well.
Required Methods
fn checked_from(value: T) -> Option<Self>
Implementations on Foreign Types
sourceimpl CheckedFrom<u8> for u8
impl CheckedFrom<u8> for u8
sourcefn checked_from(value: u8) -> Option<u8>
fn checked_from(value: u8) -> Option<u8>
Converts a value to its own type. Since this conversion is always valid and always
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for u16
impl CheckedFrom<u16> for u16
sourcefn checked_from(value: u16) -> Option<u16>
fn checked_from(value: u16) -> Option<u16>
Converts a value to its own type. Since this conversion is always valid and always
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for u32
impl CheckedFrom<u32> for u32
sourcefn checked_from(value: u32) -> Option<u32>
fn checked_from(value: u32) -> Option<u32>
Converts a value to its own type. Since this conversion is always valid and always
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for u64
impl CheckedFrom<u64> for u64
sourcefn checked_from(value: u64) -> Option<u64>
fn checked_from(value: u64) -> Option<u64>
Converts a value to its own type. Since this conversion is always valid and always
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for u128
impl CheckedFrom<u128> for u128
sourcefn checked_from(value: u128) -> Option<u128>
fn checked_from(value: u128) -> Option<u128>
Converts a value to its own type. Since this conversion is always valid and always
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for usize
impl CheckedFrom<usize> for usize
sourcefn checked_from(value: usize) -> Option<usize>
fn checked_from(value: usize) -> Option<usize>
Converts a value to its own type. Since this conversion is always valid and always
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for i8
impl CheckedFrom<i8> for i8
sourcefn checked_from(value: i8) -> Option<i8>
fn checked_from(value: i8) -> Option<i8>
Converts a value to its own type. Since this conversion is always valid and always
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for i16
impl CheckedFrom<i16> for i16
sourcefn checked_from(value: i16) -> Option<i16>
fn checked_from(value: i16) -> Option<i16>
Converts a value to its own type. Since this conversion is always valid and always
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for i32
impl CheckedFrom<i32> for i32
sourcefn checked_from(value: i32) -> Option<i32>
fn checked_from(value: i32) -> Option<i32>
Converts a value to its own type. Since this conversion is always valid and always
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for i64
impl CheckedFrom<i64> for i64
sourcefn checked_from(value: i64) -> Option<i64>
fn checked_from(value: i64) -> Option<i64>
Converts a value to its own type. Since this conversion is always valid and always
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for i128
impl CheckedFrom<i128> for i128
sourcefn checked_from(value: i128) -> Option<i128>
fn checked_from(value: i128) -> Option<i128>
Converts a value to its own type. Since this conversion is always valid and always
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for isize
impl CheckedFrom<isize> for isize
sourcefn checked_from(value: isize) -> Option<isize>
fn checked_from(value: isize) -> Option<isize>
Converts a value to its own type. Since this conversion is always valid and always
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u8> for u16
impl CheckedFrom<u8> for u16
sourcefn checked_from(value: u8) -> Option<u16>
fn checked_from(value: u8) -> Option<u16>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for u8
impl CheckedFrom<u16> for u8
sourcefn checked_from(value: u16) -> Option<u8>
fn checked_from(value: u16) -> Option<u8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u8> for u32
impl CheckedFrom<u8> for u32
sourcefn checked_from(value: u8) -> Option<u32>
fn checked_from(value: u8) -> Option<u32>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for u8
impl CheckedFrom<u32> for u8
sourcefn checked_from(value: u32) -> Option<u8>
fn checked_from(value: u32) -> Option<u8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u8> for u64
impl CheckedFrom<u8> for u64
sourcefn checked_from(value: u8) -> Option<u64>
fn checked_from(value: u8) -> Option<u64>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for u8
impl CheckedFrom<u64> for u8
sourcefn checked_from(value: u64) -> Option<u8>
fn checked_from(value: u64) -> Option<u8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u8> for u128
impl CheckedFrom<u8> for u128
sourcefn checked_from(value: u8) -> Option<u128>
fn checked_from(value: u8) -> Option<u128>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for u8
impl CheckedFrom<u128> for u8
sourcefn checked_from(value: u128) -> Option<u8>
fn checked_from(value: u128) -> Option<u8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u8> for usize
impl CheckedFrom<u8> for usize
sourcefn checked_from(value: u8) -> Option<usize>
fn checked_from(value: u8) -> Option<usize>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for u8
impl CheckedFrom<usize> for u8
sourcefn checked_from(value: usize) -> Option<u8>
fn checked_from(value: usize) -> Option<u8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u8> for i16
impl CheckedFrom<u8> for i16
sourcefn checked_from(value: u8) -> Option<i16>
fn checked_from(value: u8) -> Option<i16>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for u8
impl CheckedFrom<i16> for u8
sourcefn checked_from(value: i16) -> Option<u8>
fn checked_from(value: i16) -> Option<u8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u8> for i32
impl CheckedFrom<u8> for i32
sourcefn checked_from(value: u8) -> Option<i32>
fn checked_from(value: u8) -> Option<i32>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for u8
impl CheckedFrom<i32> for u8
sourcefn checked_from(value: i32) -> Option<u8>
fn checked_from(value: i32) -> Option<u8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u8> for i64
impl CheckedFrom<u8> for i64
sourcefn checked_from(value: u8) -> Option<i64>
fn checked_from(value: u8) -> Option<i64>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for u8
impl CheckedFrom<i64> for u8
sourcefn checked_from(value: i64) -> Option<u8>
fn checked_from(value: i64) -> Option<u8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u8> for i128
impl CheckedFrom<u8> for i128
sourcefn checked_from(value: u8) -> Option<i128>
fn checked_from(value: u8) -> Option<i128>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for u8
impl CheckedFrom<i128> for u8
sourcefn checked_from(value: i128) -> Option<u8>
fn checked_from(value: i128) -> Option<u8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u8> for isize
impl CheckedFrom<u8> for isize
sourcefn checked_from(value: u8) -> Option<isize>
fn checked_from(value: u8) -> Option<isize>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for u8
impl CheckedFrom<isize> for u8
sourcefn checked_from(value: isize) -> Option<u8>
fn checked_from(value: isize) -> Option<u8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for u32
impl CheckedFrom<u16> for u32
sourcefn checked_from(value: u16) -> Option<u32>
fn checked_from(value: u16) -> Option<u32>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for u16
impl CheckedFrom<u32> for u16
sourcefn checked_from(value: u32) -> Option<u16>
fn checked_from(value: u32) -> Option<u16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for u64
impl CheckedFrom<u16> for u64
sourcefn checked_from(value: u16) -> Option<u64>
fn checked_from(value: u16) -> Option<u64>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for u16
impl CheckedFrom<u64> for u16
sourcefn checked_from(value: u64) -> Option<u16>
fn checked_from(value: u64) -> Option<u16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for u128
impl CheckedFrom<u16> for u128
sourcefn checked_from(value: u16) -> Option<u128>
fn checked_from(value: u16) -> Option<u128>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for u16
impl CheckedFrom<u128> for u16
sourcefn checked_from(value: u128) -> Option<u16>
fn checked_from(value: u128) -> Option<u16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for usize
impl CheckedFrom<u16> for usize
sourcefn checked_from(value: u16) -> Option<usize>
fn checked_from(value: u16) -> Option<usize>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for u16
impl CheckedFrom<usize> for u16
sourcefn checked_from(value: usize) -> Option<u16>
fn checked_from(value: usize) -> Option<u16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for i32
impl CheckedFrom<u16> for i32
sourcefn checked_from(value: u16) -> Option<i32>
fn checked_from(value: u16) -> Option<i32>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for u16
impl CheckedFrom<i32> for u16
sourcefn checked_from(value: i32) -> Option<u16>
fn checked_from(value: i32) -> Option<u16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for i64
impl CheckedFrom<u16> for i64
sourcefn checked_from(value: u16) -> Option<i64>
fn checked_from(value: u16) -> Option<i64>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for u16
impl CheckedFrom<i64> for u16
sourcefn checked_from(value: i64) -> Option<u16>
fn checked_from(value: i64) -> Option<u16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for i128
impl CheckedFrom<u16> for i128
sourcefn checked_from(value: u16) -> Option<i128>
fn checked_from(value: u16) -> Option<i128>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for u16
impl CheckedFrom<i128> for u16
sourcefn checked_from(value: i128) -> Option<u16>
fn checked_from(value: i128) -> Option<u16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for u64
impl CheckedFrom<u32> for u64
sourcefn checked_from(value: u32) -> Option<u64>
fn checked_from(value: u32) -> Option<u64>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for u32
impl CheckedFrom<u64> for u32
sourcefn checked_from(value: u64) -> Option<u32>
fn checked_from(value: u64) -> Option<u32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for u128
impl CheckedFrom<u32> for u128
sourcefn checked_from(value: u32) -> Option<u128>
fn checked_from(value: u32) -> Option<u128>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for u32
impl CheckedFrom<u128> for u32
sourcefn checked_from(value: u128) -> Option<u32>
fn checked_from(value: u128) -> Option<u32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for i64
impl CheckedFrom<u32> for i64
sourcefn checked_from(value: u32) -> Option<i64>
fn checked_from(value: u32) -> Option<i64>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for u32
impl CheckedFrom<i64> for u32
sourcefn checked_from(value: i64) -> Option<u32>
fn checked_from(value: i64) -> Option<u32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for i128
impl CheckedFrom<u32> for i128
sourcefn checked_from(value: u32) -> Option<i128>
fn checked_from(value: u32) -> Option<i128>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for u32
impl CheckedFrom<i128> for u32
sourcefn checked_from(value: i128) -> Option<u32>
fn checked_from(value: i128) -> Option<u32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for u128
impl CheckedFrom<u64> for u128
sourcefn checked_from(value: u64) -> Option<u128>
fn checked_from(value: u64) -> Option<u128>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for u64
impl CheckedFrom<u128> for u64
sourcefn checked_from(value: u128) -> Option<u64>
fn checked_from(value: u128) -> Option<u64>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for i128
impl CheckedFrom<u64> for i128
sourcefn checked_from(value: u64) -> Option<i128>
fn checked_from(value: u64) -> Option<i128>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for u64
impl CheckedFrom<i128> for u64
sourcefn checked_from(value: i128) -> Option<u64>
fn checked_from(value: i128) -> Option<u64>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for i16
impl CheckedFrom<i8> for i16
sourcefn checked_from(value: i8) -> Option<i16>
fn checked_from(value: i8) -> Option<i16>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for i8
impl CheckedFrom<i16> for i8
sourcefn checked_from(value: i16) -> Option<i8>
fn checked_from(value: i16) -> Option<i8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for i32
impl CheckedFrom<i8> for i32
sourcefn checked_from(value: i8) -> Option<i32>
fn checked_from(value: i8) -> Option<i32>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for i8
impl CheckedFrom<i32> for i8
sourcefn checked_from(value: i32) -> Option<i8>
fn checked_from(value: i32) -> Option<i8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for i64
impl CheckedFrom<i8> for i64
sourcefn checked_from(value: i8) -> Option<i64>
fn checked_from(value: i8) -> Option<i64>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for i8
impl CheckedFrom<i64> for i8
sourcefn checked_from(value: i64) -> Option<i8>
fn checked_from(value: i64) -> Option<i8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for i128
impl CheckedFrom<i8> for i128
sourcefn checked_from(value: i8) -> Option<i128>
fn checked_from(value: i8) -> Option<i128>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for i8
impl CheckedFrom<i128> for i8
sourcefn checked_from(value: i128) -> Option<i8>
fn checked_from(value: i128) -> Option<i8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for isize
impl CheckedFrom<i8> for isize
sourcefn checked_from(value: i8) -> Option<isize>
fn checked_from(value: i8) -> Option<isize>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for i8
impl CheckedFrom<isize> for i8
sourcefn checked_from(value: isize) -> Option<i8>
fn checked_from(value: isize) -> Option<i8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for i32
impl CheckedFrom<i16> for i32
sourcefn checked_from(value: i16) -> Option<i32>
fn checked_from(value: i16) -> Option<i32>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for i16
impl CheckedFrom<i32> for i16
sourcefn checked_from(value: i32) -> Option<i16>
fn checked_from(value: i32) -> Option<i16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for i64
impl CheckedFrom<i16> for i64
sourcefn checked_from(value: i16) -> Option<i64>
fn checked_from(value: i16) -> Option<i64>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for i16
impl CheckedFrom<i64> for i16
sourcefn checked_from(value: i64) -> Option<i16>
fn checked_from(value: i64) -> Option<i16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for i128
impl CheckedFrom<i16> for i128
sourcefn checked_from(value: i16) -> Option<i128>
fn checked_from(value: i16) -> Option<i128>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for i16
impl CheckedFrom<i128> for i16
sourcefn checked_from(value: i128) -> Option<i16>
fn checked_from(value: i128) -> Option<i16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for isize
impl CheckedFrom<i16> for isize
sourcefn checked_from(value: i16) -> Option<isize>
fn checked_from(value: i16) -> Option<isize>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for i16
impl CheckedFrom<isize> for i16
sourcefn checked_from(value: isize) -> Option<i16>
fn checked_from(value: isize) -> Option<i16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for i64
impl CheckedFrom<i32> for i64
sourcefn checked_from(value: i32) -> Option<i64>
fn checked_from(value: i32) -> Option<i64>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for i32
impl CheckedFrom<i64> for i32
sourcefn checked_from(value: i64) -> Option<i32>
fn checked_from(value: i64) -> Option<i32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for i128
impl CheckedFrom<i32> for i128
sourcefn checked_from(value: i32) -> Option<i128>
fn checked_from(value: i32) -> Option<i128>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for i32
impl CheckedFrom<i128> for i32
sourcefn checked_from(value: i128) -> Option<i32>
fn checked_from(value: i128) -> Option<i32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for i128
impl CheckedFrom<i64> for i128
sourcefn checked_from(value: i64) -> Option<i128>
fn checked_from(value: i64) -> Option<i128>
Converts a value to another type. Since this conversion is always lossless and
leaves the value unchanged, None
is never returned.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for i64
impl CheckedFrom<i128> for i64
sourcefn checked_from(value: i128) -> Option<i64>
fn checked_from(value: i128) -> Option<i64>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u8> for i8
impl CheckedFrom<u8> for i8
sourcefn checked_from(value: u8) -> Option<i8>
fn checked_from(value: u8) -> Option<i8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for u8
impl CheckedFrom<i8> for u8
sourcefn checked_from(value: i8) -> Option<u8>
fn checked_from(value: i8) -> Option<u8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for i8
impl CheckedFrom<u16> for i8
sourcefn checked_from(value: u16) -> Option<i8>
fn checked_from(value: u16) -> Option<i8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for u16
impl CheckedFrom<i8> for u16
sourcefn checked_from(value: i8) -> Option<u16>
fn checked_from(value: i8) -> Option<u16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for i16
impl CheckedFrom<u16> for i16
sourcefn checked_from(value: u16) -> Option<i16>
fn checked_from(value: u16) -> Option<i16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for u16
impl CheckedFrom<i16> for u16
sourcefn checked_from(value: i16) -> Option<u16>
fn checked_from(value: i16) -> Option<u16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for isize
impl CheckedFrom<u16> for isize
sourcefn checked_from(value: u16) -> Option<isize>
fn checked_from(value: u16) -> Option<isize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for u16
impl CheckedFrom<isize> for u16
sourcefn checked_from(value: isize) -> Option<u16>
fn checked_from(value: isize) -> Option<u16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for usize
impl CheckedFrom<u32> for usize
sourcefn checked_from(value: u32) -> Option<usize>
fn checked_from(value: u32) -> Option<usize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for u32
impl CheckedFrom<usize> for u32
sourcefn checked_from(value: usize) -> Option<u32>
fn checked_from(value: usize) -> Option<u32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for i8
impl CheckedFrom<u32> for i8
sourcefn checked_from(value: u32) -> Option<i8>
fn checked_from(value: u32) -> Option<i8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for u32
impl CheckedFrom<i8> for u32
sourcefn checked_from(value: i8) -> Option<u32>
fn checked_from(value: i8) -> Option<u32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for i16
impl CheckedFrom<u32> for i16
sourcefn checked_from(value: u32) -> Option<i16>
fn checked_from(value: u32) -> Option<i16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for u32
impl CheckedFrom<i16> for u32
sourcefn checked_from(value: i16) -> Option<u32>
fn checked_from(value: i16) -> Option<u32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for i32
impl CheckedFrom<u32> for i32
sourcefn checked_from(value: u32) -> Option<i32>
fn checked_from(value: u32) -> Option<i32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for u32
impl CheckedFrom<i32> for u32
sourcefn checked_from(value: i32) -> Option<u32>
fn checked_from(value: i32) -> Option<u32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for isize
impl CheckedFrom<u32> for isize
sourcefn checked_from(value: u32) -> Option<isize>
fn checked_from(value: u32) -> Option<isize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for u32
impl CheckedFrom<isize> for u32
sourcefn checked_from(value: isize) -> Option<u32>
fn checked_from(value: isize) -> Option<u32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for usize
impl CheckedFrom<u64> for usize
sourcefn checked_from(value: u64) -> Option<usize>
fn checked_from(value: u64) -> Option<usize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for u64
impl CheckedFrom<usize> for u64
sourcefn checked_from(value: usize) -> Option<u64>
fn checked_from(value: usize) -> Option<u64>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for i8
impl CheckedFrom<u64> for i8
sourcefn checked_from(value: u64) -> Option<i8>
fn checked_from(value: u64) -> Option<i8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for u64
impl CheckedFrom<i8> for u64
sourcefn checked_from(value: i8) -> Option<u64>
fn checked_from(value: i8) -> Option<u64>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for i16
impl CheckedFrom<u64> for i16
sourcefn checked_from(value: u64) -> Option<i16>
fn checked_from(value: u64) -> Option<i16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for u64
impl CheckedFrom<i16> for u64
sourcefn checked_from(value: i16) -> Option<u64>
fn checked_from(value: i16) -> Option<u64>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for i32
impl CheckedFrom<u64> for i32
sourcefn checked_from(value: u64) -> Option<i32>
fn checked_from(value: u64) -> Option<i32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for u64
impl CheckedFrom<i32> for u64
sourcefn checked_from(value: i32) -> Option<u64>
fn checked_from(value: i32) -> Option<u64>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for i64
impl CheckedFrom<u64> for i64
sourcefn checked_from(value: u64) -> Option<i64>
fn checked_from(value: u64) -> Option<i64>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for u64
impl CheckedFrom<i64> for u64
sourcefn checked_from(value: i64) -> Option<u64>
fn checked_from(value: i64) -> Option<u64>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for isize
impl CheckedFrom<u64> for isize
sourcefn checked_from(value: u64) -> Option<isize>
fn checked_from(value: u64) -> Option<isize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for u64
impl CheckedFrom<isize> for u64
sourcefn checked_from(value: isize) -> Option<u64>
fn checked_from(value: isize) -> Option<u64>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for usize
impl CheckedFrom<u128> for usize
sourcefn checked_from(value: u128) -> Option<usize>
fn checked_from(value: u128) -> Option<usize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for u128
impl CheckedFrom<usize> for u128
sourcefn checked_from(value: usize) -> Option<u128>
fn checked_from(value: usize) -> Option<u128>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for i8
impl CheckedFrom<u128> for i8
sourcefn checked_from(value: u128) -> Option<i8>
fn checked_from(value: u128) -> Option<i8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for u128
impl CheckedFrom<i8> for u128
sourcefn checked_from(value: i8) -> Option<u128>
fn checked_from(value: i8) -> Option<u128>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for i16
impl CheckedFrom<u128> for i16
sourcefn checked_from(value: u128) -> Option<i16>
fn checked_from(value: u128) -> Option<i16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for u128
impl CheckedFrom<i16> for u128
sourcefn checked_from(value: i16) -> Option<u128>
fn checked_from(value: i16) -> Option<u128>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for i32
impl CheckedFrom<u128> for i32
sourcefn checked_from(value: u128) -> Option<i32>
fn checked_from(value: u128) -> Option<i32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for u128
impl CheckedFrom<i32> for u128
sourcefn checked_from(value: i32) -> Option<u128>
fn checked_from(value: i32) -> Option<u128>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for i64
impl CheckedFrom<u128> for i64
sourcefn checked_from(value: u128) -> Option<i64>
fn checked_from(value: u128) -> Option<i64>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for u128
impl CheckedFrom<i64> for u128
sourcefn checked_from(value: i64) -> Option<u128>
fn checked_from(value: i64) -> Option<u128>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for i128
impl CheckedFrom<u128> for i128
sourcefn checked_from(value: u128) -> Option<i128>
fn checked_from(value: u128) -> Option<i128>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for u128
impl CheckedFrom<i128> for u128
sourcefn checked_from(value: i128) -> Option<u128>
fn checked_from(value: i128) -> Option<u128>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for isize
impl CheckedFrom<u128> for isize
sourcefn checked_from(value: u128) -> Option<isize>
fn checked_from(value: u128) -> Option<isize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for u128
impl CheckedFrom<isize> for u128
sourcefn checked_from(value: isize) -> Option<u128>
fn checked_from(value: isize) -> Option<u128>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for i8
impl CheckedFrom<usize> for i8
sourcefn checked_from(value: usize) -> Option<i8>
fn checked_from(value: usize) -> Option<i8>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for usize
impl CheckedFrom<i8> for usize
sourcefn checked_from(value: i8) -> Option<usize>
fn checked_from(value: i8) -> Option<usize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for i16
impl CheckedFrom<usize> for i16
sourcefn checked_from(value: usize) -> Option<i16>
fn checked_from(value: usize) -> Option<i16>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for usize
impl CheckedFrom<i16> for usize
sourcefn checked_from(value: i16) -> Option<usize>
fn checked_from(value: i16) -> Option<usize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for i32
impl CheckedFrom<usize> for i32
sourcefn checked_from(value: usize) -> Option<i32>
fn checked_from(value: usize) -> Option<i32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for usize
impl CheckedFrom<i32> for usize
sourcefn checked_from(value: i32) -> Option<usize>
fn checked_from(value: i32) -> Option<usize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for i64
impl CheckedFrom<usize> for i64
sourcefn checked_from(value: usize) -> Option<i64>
fn checked_from(value: usize) -> Option<i64>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for usize
impl CheckedFrom<i64> for usize
sourcefn checked_from(value: i64) -> Option<usize>
fn checked_from(value: i64) -> Option<usize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for i128
impl CheckedFrom<usize> for i128
sourcefn checked_from(value: usize) -> Option<i128>
fn checked_from(value: usize) -> Option<i128>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for usize
impl CheckedFrom<i128> for usize
sourcefn checked_from(value: i128) -> Option<usize>
fn checked_from(value: i128) -> Option<usize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for isize
impl CheckedFrom<usize> for isize
sourcefn checked_from(value: usize) -> Option<isize>
fn checked_from(value: usize) -> Option<isize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for usize
impl CheckedFrom<isize> for usize
sourcefn checked_from(value: isize) -> Option<usize>
fn checked_from(value: isize) -> Option<usize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for isize
impl CheckedFrom<i32> for isize
sourcefn checked_from(value: i32) -> Option<isize>
fn checked_from(value: i32) -> Option<isize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for i32
impl CheckedFrom<isize> for i32
sourcefn checked_from(value: isize) -> Option<i32>
fn checked_from(value: isize) -> Option<i32>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for isize
impl CheckedFrom<i64> for isize
sourcefn checked_from(value: i64) -> Option<isize>
fn checked_from(value: i64) -> Option<isize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for i64
impl CheckedFrom<isize> for i64
sourcefn checked_from(value: isize) -> Option<i64>
fn checked_from(value: isize) -> Option<i64>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for isize
impl CheckedFrom<i128> for isize
sourcefn checked_from(value: i128) -> Option<isize>
fn checked_from(value: i128) -> Option<isize>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for i128
impl CheckedFrom<isize> for i128
sourcefn checked_from(value: isize) -> Option<i128>
fn checked_from(value: isize) -> Option<i128>
Converts a value to another type. If the value cannot be represented in the new
type, None
is returned.
Let $W$ be the width of the target type.
If the target type is unsigned, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad 0 \leq n < 2^W, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
If the target type is signed, then $$ f_W(n) = \begin{cases} \operatorname{Some}(n) & \text{if} \quad -2^{W-1} \leq n < 2^{W-1}-1, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u8> for f32
impl CheckedFrom<u8> for f32
sourcefn checked_from(value: u8) -> Option<f32>
fn checked_from(value: u8) -> Option<f32>
Converts a value of an unsigned type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f32> for u8
impl CheckedFrom<f32> for u8
sourcefn checked_from(value: f32) -> Option<u8>
fn checked_from(value: f32) -> Option<u8>
Converts a value of a floating point type to a value of an unsigned type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u8> for f64
impl CheckedFrom<u8> for f64
sourcefn checked_from(value: u8) -> Option<f64>
fn checked_from(value: u8) -> Option<f64>
Converts a value of an unsigned type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f64> for u8
impl CheckedFrom<f64> for u8
sourcefn checked_from(value: f64) -> Option<u8>
fn checked_from(value: f64) -> Option<u8>
Converts a value of a floating point type to a value of an unsigned type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for f32
impl CheckedFrom<u16> for f32
sourcefn checked_from(value: u16) -> Option<f32>
fn checked_from(value: u16) -> Option<f32>
Converts a value of an unsigned type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f32> for u16
impl CheckedFrom<f32> for u16
sourcefn checked_from(value: f32) -> Option<u16>
fn checked_from(value: f32) -> Option<u16>
Converts a value of a floating point type to a value of an unsigned type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u16> for f64
impl CheckedFrom<u16> for f64
sourcefn checked_from(value: u16) -> Option<f64>
fn checked_from(value: u16) -> Option<f64>
Converts a value of an unsigned type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f64> for u16
impl CheckedFrom<f64> for u16
sourcefn checked_from(value: f64) -> Option<u16>
fn checked_from(value: f64) -> Option<u16>
Converts a value of a floating point type to a value of an unsigned type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for f32
impl CheckedFrom<u32> for f32
sourcefn checked_from(value: u32) -> Option<f32>
fn checked_from(value: u32) -> Option<f32>
Converts a value of an unsigned type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f32> for u32
impl CheckedFrom<f32> for u32
sourcefn checked_from(value: f32) -> Option<u32>
fn checked_from(value: f32) -> Option<u32>
Converts a value of a floating point type to a value of an unsigned type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u32> for f64
impl CheckedFrom<u32> for f64
sourcefn checked_from(value: u32) -> Option<f64>
fn checked_from(value: u32) -> Option<f64>
Converts a value of an unsigned type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f64> for u32
impl CheckedFrom<f64> for u32
sourcefn checked_from(value: f64) -> Option<u32>
fn checked_from(value: f64) -> Option<u32>
Converts a value of a floating point type to a value of an unsigned type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for f32
impl CheckedFrom<u64> for f32
sourcefn checked_from(value: u64) -> Option<f32>
fn checked_from(value: u64) -> Option<f32>
Converts a value of an unsigned type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f32> for u64
impl CheckedFrom<f32> for u64
sourcefn checked_from(value: f32) -> Option<u64>
fn checked_from(value: f32) -> Option<u64>
Converts a value of a floating point type to a value of an unsigned type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u64> for f64
impl CheckedFrom<u64> for f64
sourcefn checked_from(value: u64) -> Option<f64>
fn checked_from(value: u64) -> Option<f64>
Converts a value of an unsigned type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f64> for u64
impl CheckedFrom<f64> for u64
sourcefn checked_from(value: f64) -> Option<u64>
fn checked_from(value: f64) -> Option<u64>
Converts a value of a floating point type to a value of an unsigned type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for f32
impl CheckedFrom<u128> for f32
sourcefn checked_from(value: u128) -> Option<f32>
fn checked_from(value: u128) -> Option<f32>
Converts a value of an unsigned type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f32> for u128
impl CheckedFrom<f32> for u128
sourcefn checked_from(value: f32) -> Option<u128>
fn checked_from(value: f32) -> Option<u128>
Converts a value of a floating point type to a value of an unsigned type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<u128> for f64
impl CheckedFrom<u128> for f64
sourcefn checked_from(value: u128) -> Option<f64>
fn checked_from(value: u128) -> Option<f64>
Converts a value of an unsigned type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f64> for u128
impl CheckedFrom<f64> for u128
sourcefn checked_from(value: f64) -> Option<u128>
fn checked_from(value: f64) -> Option<u128>
Converts a value of a floating point type to a value of an unsigned type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for f32
impl CheckedFrom<usize> for f32
sourcefn checked_from(value: usize) -> Option<f32>
fn checked_from(value: usize) -> Option<f32>
Converts a value of an unsigned type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f32> for usize
impl CheckedFrom<f32> for usize
sourcefn checked_from(value: f32) -> Option<usize>
fn checked_from(value: f32) -> Option<usize>
Converts a value of a floating point type to a value of an unsigned type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<usize> for f64
impl CheckedFrom<usize> for f64
sourcefn checked_from(value: usize) -> Option<f64>
fn checked_from(value: usize) -> Option<f64>
Converts a value of an unsigned type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the unsigned value is not too large to represent
(which can only happen when converting a u128
to an f32
) and the
precision of the unsigned value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f64> for usize
impl CheckedFrom<f64> for usize
sourcefn checked_from(value: f64) -> Option<usize>
fn checked_from(value: f64) -> Option<usize>
Converts a value of a floating point type to a value of an unsigned type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer, not negative (negative zero is ok), and not too large.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for f32
impl CheckedFrom<i8> for f32
sourcefn checked_from(value: i8) -> Option<f32>
fn checked_from(value: i8) -> Option<f32>
Converts a value of a signed type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f32> for i8
impl CheckedFrom<f32> for i8
sourcefn checked_from(value: f32) -> Option<i8>
fn checked_from(value: f32) -> Option<i8>
Converts a value of a floating point type to a value of a signed type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i8> for f64
impl CheckedFrom<i8> for f64
sourcefn checked_from(value: i8) -> Option<f64>
fn checked_from(value: i8) -> Option<f64>
Converts a value of a signed type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f64> for i8
impl CheckedFrom<f64> for i8
sourcefn checked_from(value: f64) -> Option<i8>
fn checked_from(value: f64) -> Option<i8>
Converts a value of a floating point type to a value of a signed type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for f32
impl CheckedFrom<i16> for f32
sourcefn checked_from(value: i16) -> Option<f32>
fn checked_from(value: i16) -> Option<f32>
Converts a value of a signed type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f32> for i16
impl CheckedFrom<f32> for i16
sourcefn checked_from(value: f32) -> Option<i16>
fn checked_from(value: f32) -> Option<i16>
Converts a value of a floating point type to a value of a signed type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i16> for f64
impl CheckedFrom<i16> for f64
sourcefn checked_from(value: i16) -> Option<f64>
fn checked_from(value: i16) -> Option<f64>
Converts a value of a signed type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f64> for i16
impl CheckedFrom<f64> for i16
sourcefn checked_from(value: f64) -> Option<i16>
fn checked_from(value: f64) -> Option<i16>
Converts a value of a floating point type to a value of a signed type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for f32
impl CheckedFrom<i32> for f32
sourcefn checked_from(value: i32) -> Option<f32>
fn checked_from(value: i32) -> Option<f32>
Converts a value of a signed type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f32> for i32
impl CheckedFrom<f32> for i32
sourcefn checked_from(value: f32) -> Option<i32>
fn checked_from(value: f32) -> Option<i32>
Converts a value of a floating point type to a value of a signed type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i32> for f64
impl CheckedFrom<i32> for f64
sourcefn checked_from(value: i32) -> Option<f64>
fn checked_from(value: i32) -> Option<f64>
Converts a value of a signed type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f64> for i32
impl CheckedFrom<f64> for i32
sourcefn checked_from(value: f64) -> Option<i32>
fn checked_from(value: f64) -> Option<i32>
Converts a value of a floating point type to a value of a signed type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for f32
impl CheckedFrom<i64> for f32
sourcefn checked_from(value: i64) -> Option<f32>
fn checked_from(value: i64) -> Option<f32>
Converts a value of a signed type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f32> for i64
impl CheckedFrom<f32> for i64
sourcefn checked_from(value: f32) -> Option<i64>
fn checked_from(value: f32) -> Option<i64>
Converts a value of a floating point type to a value of a signed type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i64> for f64
impl CheckedFrom<i64> for f64
sourcefn checked_from(value: i64) -> Option<f64>
fn checked_from(value: i64) -> Option<f64>
Converts a value of a signed type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f64> for i64
impl CheckedFrom<f64> for i64
sourcefn checked_from(value: f64) -> Option<i64>
fn checked_from(value: f64) -> Option<i64>
Converts a value of a floating point type to a value of a signed type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for f32
impl CheckedFrom<i128> for f32
sourcefn checked_from(value: i128) -> Option<f32>
fn checked_from(value: i128) -> Option<f32>
Converts a value of a signed type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f32> for i128
impl CheckedFrom<f32> for i128
sourcefn checked_from(value: f32) -> Option<i128>
fn checked_from(value: f32) -> Option<i128>
Converts a value of a floating point type to a value of a signed type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<i128> for f64
impl CheckedFrom<i128> for f64
sourcefn checked_from(value: i128) -> Option<f64>
fn checked_from(value: i128) -> Option<f64>
Converts a value of a signed type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f64> for i128
impl CheckedFrom<f64> for i128
sourcefn checked_from(value: f64) -> Option<i128>
fn checked_from(value: f64) -> Option<i128>
Converts a value of a floating point type to a value of a signed type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for f32
impl CheckedFrom<isize> for f32
sourcefn checked_from(value: isize) -> Option<f32>
fn checked_from(value: isize) -> Option<f32>
Converts a value of a signed type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f32> for isize
impl CheckedFrom<f32> for isize
sourcefn checked_from(value: f32) -> Option<isize>
fn checked_from(value: f32) -> Option<isize>
Converts a value of a floating point type to a value of a signed type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<isize> for f64
impl CheckedFrom<isize> for f64
sourcefn checked_from(value: isize) -> Option<f64>
fn checked_from(value: isize) -> Option<f64>
Converts a value of a signed type to a value of a floating point type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the precision of the signed value is not too high.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl CheckedFrom<f64> for isize
impl CheckedFrom<f64> for isize
sourcefn checked_from(value: f64) -> Option<isize>
fn checked_from(value: f64) -> Option<isize>
Converts a value of a floating point type to a value of a signed type,
returning None
if an exact conversion is not possible.
The conversion succeeds if the floating point value is an integer and not too large or too small.
Worst-case complexity
Constant time and additional memory.
Examples
See here.