Trait malachite_base::num::conversion::traits::FromOtherTypeSlice
source · pub trait FromOtherTypeSlice<T: Sized> {
// Required method
fn from_other_type_slice(slice: &[T]) -> Self;
}
Expand description
Converts a slice of one type of value to a single value of another type.
Required Methods§
fn from_other_type_slice(slice: &[T]) -> Self
Object Safety§
Implementations on Foreign Types§
source§impl FromOtherTypeSlice<u8> for u8
impl FromOtherTypeSlice<u8> for u8
source§fn from_other_type_slice(xs: &[u8]) -> Self
fn from_other_type_slice(xs: &[u8]) -> Self
Converts a slice of one type of value to a single value of the same type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ x_0 & \text{otherwise}, \end{cases} $$ where $W$ is the width of the type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If there’s more than one element in the input slice, the value wraps and all elements past the first are ignored. This means that if the slice is empty, the output value is 0; otherwise, it’s the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u8> for u16
impl FromOtherTypeSlice<u8> for u16
source§fn from_other_type_slice(xs: &[u8]) -> Self
fn from_other_type_slice(xs: &[u8]) -> Self
Converts a slice of one type of unsigned integer to a single value of a larger unsigned type.
Let $V$ be the the width of the input type and $W$ the width of the output type.
$f((x_k)_{k=0}^{n-1}) = y$, where $y < 2^W$ and
$$ y = k2^W + \sum_{j=0}^{n-1}2^{jV}x_j $$
for some integer $k$.
If the input slice contains more values than necessary to build an output value, the trailing values are ignored. If the input slice contains too few values to build an output value, the most-significant bits of the output value are set to 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u8> for u32
impl FromOtherTypeSlice<u8> for u32
source§fn from_other_type_slice(xs: &[u8]) -> Self
fn from_other_type_slice(xs: &[u8]) -> Self
Converts a slice of one type of unsigned integer to a single value of a larger unsigned type.
Let $V$ be the the width of the input type and $W$ the width of the output type.
$f((x_k)_{k=0}^{n-1}) = y$, where $y < 2^W$ and
$$ y = k2^W + \sum_{j=0}^{n-1}2^{jV}x_j $$
for some integer $k$.
If the input slice contains more values than necessary to build an output value, the trailing values are ignored. If the input slice contains too few values to build an output value, the most-significant bits of the output value are set to 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u8> for u64
impl FromOtherTypeSlice<u8> for u64
source§fn from_other_type_slice(xs: &[u8]) -> Self
fn from_other_type_slice(xs: &[u8]) -> Self
Converts a slice of one type of unsigned integer to a single value of a larger unsigned type.
Let $V$ be the the width of the input type and $W$ the width of the output type.
$f((x_k)_{k=0}^{n-1}) = y$, where $y < 2^W$ and
$$ y = k2^W + \sum_{j=0}^{n-1}2^{jV}x_j $$
for some integer $k$.
If the input slice contains more values than necessary to build an output value, the trailing values are ignored. If the input slice contains too few values to build an output value, the most-significant bits of the output value are set to 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u8> for u128
impl FromOtherTypeSlice<u8> for u128
source§fn from_other_type_slice(xs: &[u8]) -> Self
fn from_other_type_slice(xs: &[u8]) -> Self
Converts a slice of one type of unsigned integer to a single value of a larger unsigned type.
Let $V$ be the the width of the input type and $W$ the width of the output type.
$f((x_k)_{k=0}^{n-1}) = y$, where $y < 2^W$ and
$$ y = k2^W + \sum_{j=0}^{n-1}2^{jV}x_j $$
for some integer $k$.
If the input slice contains more values than necessary to build an output value, the trailing values are ignored. If the input slice contains too few values to build an output value, the most-significant bits of the output value are set to 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u8> for usize
impl FromOtherTypeSlice<u8> for usize
source§fn from_other_type_slice(xs: &[u8]) -> Self
fn from_other_type_slice(xs: &[u8]) -> Self
Converts a slice of one type of unsigned integer to a single value of a larger unsigned type.
Let $V$ be the the width of the input type and $W$ the width of the output type.
$f((x_k)_{k=0}^{n-1}) = y$, where $y < 2^W$ and
$$ y = k2^W + \sum_{j=0}^{n-1}2^{jV}x_j $$
for some integer $k$.
If the input slice contains more values than necessary to build an output value, the trailing values are ignored. If the input slice contains too few values to build an output value, the most-significant bits of the output value are set to 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u16> for u8
impl FromOtherTypeSlice<u16> for u8
source§fn from_other_type_slice(xs: &[u16]) -> Self
fn from_other_type_slice(xs: &[u16]) -> Self
Converts a slice of one type of unsigned integer to a single value of a smaller unsigned type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ y & \text{otherwise}, \end{cases} $$ where $0 \leq y < 2^W$, $x = y + k2^W$ for some integer $k$, and $W$ is the width of the output type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If the slice is empty, the output value is 0; otherwise, it consists of the least-significant bits of the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u16> for u16
impl FromOtherTypeSlice<u16> for u16
source§fn from_other_type_slice(xs: &[u16]) -> Self
fn from_other_type_slice(xs: &[u16]) -> Self
Converts a slice of one type of value to a single value of the same type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ x_0 & \text{otherwise}, \end{cases} $$ where $W$ is the width of the type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If there’s more than one element in the input slice, the value wraps and all elements past the first are ignored. This means that if the slice is empty, the output value is 0; otherwise, it’s the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u16> for u32
impl FromOtherTypeSlice<u16> for u32
source§fn from_other_type_slice(xs: &[u16]) -> Self
fn from_other_type_slice(xs: &[u16]) -> Self
Converts a slice of one type of unsigned integer to a single value of a larger unsigned type.
Let $V$ be the the width of the input type and $W$ the width of the output type.
$f((x_k)_{k=0}^{n-1}) = y$, where $y < 2^W$ and
$$ y = k2^W + \sum_{j=0}^{n-1}2^{jV}x_j $$
for some integer $k$.
If the input slice contains more values than necessary to build an output value, the trailing values are ignored. If the input slice contains too few values to build an output value, the most-significant bits of the output value are set to 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u16> for u64
impl FromOtherTypeSlice<u16> for u64
source§fn from_other_type_slice(xs: &[u16]) -> Self
fn from_other_type_slice(xs: &[u16]) -> Self
Converts a slice of one type of unsigned integer to a single value of a larger unsigned type.
Let $V$ be the the width of the input type and $W$ the width of the output type.
$f((x_k)_{k=0}^{n-1}) = y$, where $y < 2^W$ and
$$ y = k2^W + \sum_{j=0}^{n-1}2^{jV}x_j $$
for some integer $k$.
If the input slice contains more values than necessary to build an output value, the trailing values are ignored. If the input slice contains too few values to build an output value, the most-significant bits of the output value are set to 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u16> for u128
impl FromOtherTypeSlice<u16> for u128
source§fn from_other_type_slice(xs: &[u16]) -> Self
fn from_other_type_slice(xs: &[u16]) -> Self
Converts a slice of one type of unsigned integer to a single value of a larger unsigned type.
Let $V$ be the the width of the input type and $W$ the width of the output type.
$f((x_k)_{k=0}^{n-1}) = y$, where $y < 2^W$ and
$$ y = k2^W + \sum_{j=0}^{n-1}2^{jV}x_j $$
for some integer $k$.
If the input slice contains more values than necessary to build an output value, the trailing values are ignored. If the input slice contains too few values to build an output value, the most-significant bits of the output value are set to 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u16> for usize
impl FromOtherTypeSlice<u16> for usize
source§fn from_other_type_slice(xs: &[u16]) -> Self
fn from_other_type_slice(xs: &[u16]) -> Self
Converts a slice of one type of unsigned integer to a single value of a larger unsigned type.
Let $V$ be the the width of the input type and $W$ the width of the output type.
$f((x_k)_{k=0}^{n-1}) = y$, where $y < 2^W$ and
$$ y = k2^W + \sum_{j=0}^{n-1}2^{jV}x_j $$
for some integer $k$.
If the input slice contains more values than necessary to build an output value, the trailing values are ignored. If the input slice contains too few values to build an output value, the most-significant bits of the output value are set to 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u32> for u8
impl FromOtherTypeSlice<u32> for u8
source§fn from_other_type_slice(xs: &[u32]) -> Self
fn from_other_type_slice(xs: &[u32]) -> Self
Converts a slice of one type of unsigned integer to a single value of a smaller unsigned type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ y & \text{otherwise}, \end{cases} $$ where $0 \leq y < 2^W$, $x = y + k2^W$ for some integer $k$, and $W$ is the width of the output type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If the slice is empty, the output value is 0; otherwise, it consists of the least-significant bits of the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u32> for u16
impl FromOtherTypeSlice<u32> for u16
source§fn from_other_type_slice(xs: &[u32]) -> Self
fn from_other_type_slice(xs: &[u32]) -> Self
Converts a slice of one type of unsigned integer to a single value of a smaller unsigned type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ y & \text{otherwise}, \end{cases} $$ where $0 \leq y < 2^W$, $x = y + k2^W$ for some integer $k$, and $W$ is the width of the output type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If the slice is empty, the output value is 0; otherwise, it consists of the least-significant bits of the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u32> for u32
impl FromOtherTypeSlice<u32> for u32
source§fn from_other_type_slice(xs: &[u32]) -> Self
fn from_other_type_slice(xs: &[u32]) -> Self
Converts a slice of one type of value to a single value of the same type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ x_0 & \text{otherwise}, \end{cases} $$ where $W$ is the width of the type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If there’s more than one element in the input slice, the value wraps and all elements past the first are ignored. This means that if the slice is empty, the output value is 0; otherwise, it’s the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u32> for u64
impl FromOtherTypeSlice<u32> for u64
source§fn from_other_type_slice(xs: &[u32]) -> Self
fn from_other_type_slice(xs: &[u32]) -> Self
Converts a slice of one type of unsigned integer to a single value of a larger unsigned type.
Let $V$ be the the width of the input type and $W$ the width of the output type.
$f((x_k)_{k=0}^{n-1}) = y$, where $y < 2^W$ and
$$ y = k2^W + \sum_{j=0}^{n-1}2^{jV}x_j $$
for some integer $k$.
If the input slice contains more values than necessary to build an output value, the trailing values are ignored. If the input slice contains too few values to build an output value, the most-significant bits of the output value are set to 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u32> for u128
impl FromOtherTypeSlice<u32> for u128
source§fn from_other_type_slice(xs: &[u32]) -> Self
fn from_other_type_slice(xs: &[u32]) -> Self
Converts a slice of one type of unsigned integer to a single value of a larger unsigned type.
Let $V$ be the the width of the input type and $W$ the width of the output type.
$f((x_k)_{k=0}^{n-1}) = y$, where $y < 2^W$ and
$$ y = k2^W + \sum_{j=0}^{n-1}2^{jV}x_j $$
for some integer $k$.
If the input slice contains more values than necessary to build an output value, the trailing values are ignored. If the input slice contains too few values to build an output value, the most-significant bits of the output value are set to 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u32> for usize
impl FromOtherTypeSlice<u32> for usize
source§impl FromOtherTypeSlice<u64> for u8
impl FromOtherTypeSlice<u64> for u8
source§fn from_other_type_slice(xs: &[u64]) -> Self
fn from_other_type_slice(xs: &[u64]) -> Self
Converts a slice of one type of unsigned integer to a single value of a smaller unsigned type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ y & \text{otherwise}, \end{cases} $$ where $0 \leq y < 2^W$, $x = y + k2^W$ for some integer $k$, and $W$ is the width of the output type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If the slice is empty, the output value is 0; otherwise, it consists of the least-significant bits of the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u64> for u16
impl FromOtherTypeSlice<u64> for u16
source§fn from_other_type_slice(xs: &[u64]) -> Self
fn from_other_type_slice(xs: &[u64]) -> Self
Converts a slice of one type of unsigned integer to a single value of a smaller unsigned type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ y & \text{otherwise}, \end{cases} $$ where $0 \leq y < 2^W$, $x = y + k2^W$ for some integer $k$, and $W$ is the width of the output type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If the slice is empty, the output value is 0; otherwise, it consists of the least-significant bits of the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u64> for u32
impl FromOtherTypeSlice<u64> for u32
source§fn from_other_type_slice(xs: &[u64]) -> Self
fn from_other_type_slice(xs: &[u64]) -> Self
Converts a slice of one type of unsigned integer to a single value of a smaller unsigned type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ y & \text{otherwise}, \end{cases} $$ where $0 \leq y < 2^W$, $x = y + k2^W$ for some integer $k$, and $W$ is the width of the output type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If the slice is empty, the output value is 0; otherwise, it consists of the least-significant bits of the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u64> for u64
impl FromOtherTypeSlice<u64> for u64
source§fn from_other_type_slice(xs: &[u64]) -> Self
fn from_other_type_slice(xs: &[u64]) -> Self
Converts a slice of one type of value to a single value of the same type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ x_0 & \text{otherwise}, \end{cases} $$ where $W$ is the width of the type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If there’s more than one element in the input slice, the value wraps and all elements past the first are ignored. This means that if the slice is empty, the output value is 0; otherwise, it’s the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u64> for u128
impl FromOtherTypeSlice<u64> for u128
source§fn from_other_type_slice(xs: &[u64]) -> Self
fn from_other_type_slice(xs: &[u64]) -> Self
Converts a slice of one type of unsigned integer to a single value of a larger unsigned type.
Let $V$ be the the width of the input type and $W$ the width of the output type.
$f((x_k)_{k=0}^{n-1}) = y$, where $y < 2^W$ and
$$ y = k2^W + \sum_{j=0}^{n-1}2^{jV}x_j $$
for some integer $k$.
If the input slice contains more values than necessary to build an output value, the trailing values are ignored. If the input slice contains too few values to build an output value, the most-significant bits of the output value are set to 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u64> for usize
impl FromOtherTypeSlice<u64> for usize
source§impl FromOtherTypeSlice<u128> for u8
impl FromOtherTypeSlice<u128> for u8
source§fn from_other_type_slice(xs: &[u128]) -> Self
fn from_other_type_slice(xs: &[u128]) -> Self
Converts a slice of one type of unsigned integer to a single value of a smaller unsigned type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ y & \text{otherwise}, \end{cases} $$ where $0 \leq y < 2^W$, $x = y + k2^W$ for some integer $k$, and $W$ is the width of the output type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If the slice is empty, the output value is 0; otherwise, it consists of the least-significant bits of the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u128> for u16
impl FromOtherTypeSlice<u128> for u16
source§fn from_other_type_slice(xs: &[u128]) -> Self
fn from_other_type_slice(xs: &[u128]) -> Self
Converts a slice of one type of unsigned integer to a single value of a smaller unsigned type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ y & \text{otherwise}, \end{cases} $$ where $0 \leq y < 2^W$, $x = y + k2^W$ for some integer $k$, and $W$ is the width of the output type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If the slice is empty, the output value is 0; otherwise, it consists of the least-significant bits of the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u128> for u32
impl FromOtherTypeSlice<u128> for u32
source§fn from_other_type_slice(xs: &[u128]) -> Self
fn from_other_type_slice(xs: &[u128]) -> Self
Converts a slice of one type of unsigned integer to a single value of a smaller unsigned type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ y & \text{otherwise}, \end{cases} $$ where $0 \leq y < 2^W$, $x = y + k2^W$ for some integer $k$, and $W$ is the width of the output type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If the slice is empty, the output value is 0; otherwise, it consists of the least-significant bits of the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u128> for u64
impl FromOtherTypeSlice<u128> for u64
source§fn from_other_type_slice(xs: &[u128]) -> Self
fn from_other_type_slice(xs: &[u128]) -> Self
Converts a slice of one type of unsigned integer to a single value of a smaller unsigned type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ y & \text{otherwise}, \end{cases} $$ where $0 \leq y < 2^W$, $x = y + k2^W$ for some integer $k$, and $W$ is the width of the output type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If the slice is empty, the output value is 0; otherwise, it consists of the least-significant bits of the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u128> for u128
impl FromOtherTypeSlice<u128> for u128
source§fn from_other_type_slice(xs: &[u128]) -> Self
fn from_other_type_slice(xs: &[u128]) -> Self
Converts a slice of one type of value to a single value of the same type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ x_0 & \text{otherwise}, \end{cases} $$ where $W$ is the width of the type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If there’s more than one element in the input slice, the value wraps and all elements past the first are ignored. This means that if the slice is empty, the output value is 0; otherwise, it’s the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<u128> for usize
impl FromOtherTypeSlice<u128> for usize
source§fn from_other_type_slice(xs: &[u128]) -> Self
fn from_other_type_slice(xs: &[u128]) -> Self
Converts a slice of one type of unsigned integer to a single value of a smaller unsigned type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ y & \text{otherwise}, \end{cases} $$ where $0 \leq y < 2^W$, $x = y + k2^W$ for some integer $k$, and $W$ is the width of the output type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If the slice is empty, the output value is 0; otherwise, it consists of the least-significant bits of the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<usize> for u8
impl FromOtherTypeSlice<usize> for u8
source§fn from_other_type_slice(xs: &[usize]) -> Self
fn from_other_type_slice(xs: &[usize]) -> Self
Converts a slice of one type of unsigned integer to a single value of a smaller unsigned type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ y & \text{otherwise}, \end{cases} $$ where $0 \leq y < 2^W$, $x = y + k2^W$ for some integer $k$, and $W$ is the width of the output type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If the slice is empty, the output value is 0; otherwise, it consists of the least-significant bits of the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<usize> for u16
impl FromOtherTypeSlice<usize> for u16
source§fn from_other_type_slice(xs: &[usize]) -> Self
fn from_other_type_slice(xs: &[usize]) -> Self
Converts a slice of one type of unsigned integer to a single value of a smaller unsigned type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ y & \text{otherwise}, \end{cases} $$ where $0 \leq y < 2^W$, $x = y + k2^W$ for some integer $k$, and $W$ is the width of the output type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If the slice is empty, the output value is 0; otherwise, it consists of the least-significant bits of the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<usize> for u32
impl FromOtherTypeSlice<usize> for u32
source§impl FromOtherTypeSlice<usize> for u64
impl FromOtherTypeSlice<usize> for u64
source§impl FromOtherTypeSlice<usize> for u128
impl FromOtherTypeSlice<usize> for u128
source§fn from_other_type_slice(xs: &[usize]) -> Self
fn from_other_type_slice(xs: &[usize]) -> Self
Converts a slice of one type of unsigned integer to a single value of a larger unsigned type.
Let $V$ be the the width of the input type and $W$ the width of the output type.
$f((x_k)_{k=0}^{n-1}) = y$, where $y < 2^W$ and
$$ y = k2^W + \sum_{j=0}^{n-1}2^{jV}x_j $$
for some integer $k$.
If the input slice contains more values than necessary to build an output value, the trailing values are ignored. If the input slice contains too few values to build an output value, the most-significant bits of the output value are set to 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl FromOtherTypeSlice<usize> for usize
impl FromOtherTypeSlice<usize> for usize
source§fn from_other_type_slice(xs: &[usize]) -> Self
fn from_other_type_slice(xs: &[usize]) -> Self
Converts a slice of one type of value to a single value of the same type.
$$ f((x_k)_{k=0}^{n-1}) = \begin{cases} 0 & \text{if} \quad n = 0, \\ x_0 & \text{otherwise}, \end{cases} $$ where $W$ is the width of the type.
The slice is interpreted as the base-$2^W$ digits of the value, in ascending order, where $W$ is the width of the type. If there’s more than one element in the input slice, the value wraps and all elements past the first are ignored. This means that if the slice is empty, the output value is 0; otherwise, it’s the first element of the slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.