pub struct i4(/* private fields */);Expand description
The 4-bit signed integer type.
Implementations§
Source§impl i4
impl i4
Sourcepub const MIN: i4
pub const MIN: i4
The smallest value that can be represented by this integer type.
§Examples
Basic usage:
assert_eq!(i4::MIN, i4::try_from(-8i8).unwrap());Sourcepub const MAX: i4
pub const MAX: i4
The largest value that can be represented by this integer type.
§Examples
Basic usage:
assert_eq!(i4::MAX, i4::try_from(7i8).unwrap());Sourcepub fn from_be_bytes(bytes: [u8; 1]) -> Self
pub fn from_be_bytes(bytes: [u8; 1]) -> Self
Create a native endian integer value from its representation as a byte array in big endian.
Sourcepub fn from_le_bytes(bytes: [u8; 1]) -> Self
pub fn from_le_bytes(bytes: [u8; 1]) -> Self
Create a native endian integer value from its representation as a byte array in little endian.
Sourcepub fn from_ne_bytes(bytes: [u8; 1]) -> Self
pub fn from_ne_bytes(bytes: [u8; 1]) -> Self
Create a native endian integer value from its memory representation as a byte array in native endianness.
As the target platform’s native endianness is used, portable code likely
wants to use from_be_bytes or from_le_bytes, as appropriate instead.
Sourcepub fn to_be_bytes(self) -> [u8; 1]
pub fn to_be_bytes(self) -> [u8; 1]
Return the memory representation of this integer as a byte array in big-endian (network) byte order.
Unused bits are undefined.
Sourcepub fn to_le_bytes(self) -> [u8; 1]
pub fn to_le_bytes(self) -> [u8; 1]
Return the memory representation of this integer as a byte array in little-endian byte order.
Unused bits are undefined.
Sourcepub fn to_ne_bytes(self) -> [u8; 1]
pub fn to_ne_bytes(self) -> [u8; 1]
Return the memory representation of this integer as a byte array in native byte order.
As the target platform’s native endianness is used, portable code should
use to_be_bytes or to_le_bytes, as appropriate, instead.
Unused bits are undefined.
Sourcepub fn from_str_radix(src: &str, radix: u32) -> Result<i4, ParseIntError>
pub fn from_str_radix(src: &str, radix: u32) -> Result<i4, ParseIntError>
Converts a string slice in a given base to an integer.
The string is expected to be an optional + sign followed by digits. Leading and trailing whitespace represent an error. Digits are a subset of these characters, depending on radix:
0-9a-zA-Z
§Panics
This function panics if radix is not in the range from 2 to 36.
Sourcepub fn pow(self, exp: u32) -> i4
pub fn pow(self, exp: u32) -> i4
Raises self to the power of exp, using exponentiation by squaring.
Sourcepub fn checked_add(self, rhs: i4) -> Option<i4>
pub fn checked_add(self, rhs: i4) -> Option<i4>
Checked integer addition. Computes self + rhs, returning None if overflow occurred.
Sourcepub fn checked_div(self, rhs: i4) -> Option<i4>
pub fn checked_div(self, rhs: i4) -> Option<i4>
Checked integer division. Computes self / rhs, returning None if rhs == 0.
Sourcepub fn checked_mul(self, rhs: i4) -> Option<i4>
pub fn checked_mul(self, rhs: i4) -> Option<i4>
Checked integer multiplication. Computes self * rhs, returning None if overflow occurred.
Sourcepub fn checked_sub(self, rhs: i4) -> Option<i4>
pub fn checked_sub(self, rhs: i4) -> Option<i4>
Checked integer subtraction. Computes self - rhs, returning None if overflow occurred.
Sourcepub fn wrapping_add(self, rhs: i4) -> i4
pub fn wrapping_add(self, rhs: i4) -> i4
Wrapping (modular) addition. Computes self + rhs, wrapping around at
the boundary of the type.
§Examples
Basic usage:
assert_eq!(i4::MIN.wrapping_add(i4::try_from(-1i8).unwrap()), i4::MAX);Sourcepub fn wrapping_sub(self, rhs: i4) -> i4
pub fn wrapping_sub(self, rhs: i4) -> i4
Wrapping (modular) subtraction. Computes self - rhs, wrapping around
at the boundary of the type.