pub trait Integer: Numeric {
const NUM_BITS: usize;
// Required methods
fn ZERO() -> Self;
fn ONE() -> Self;
fn TWO() -> Self;
fn from_literal(val: u128) -> Self;
fn from_hex_string(s: &String) -> Self;
fn get_bit(self, i: usize) -> Self;
fn set_bit(self, b: Self, i: usize) -> Self;
fn set(self, pos: usize, y: Self, yi: usize) -> Self;
fn rotate_left(self, n: usize) -> Self;
fn rotate_right(self, n: usize) -> Self;
}
Expand description
This trait extends the Numeric
trait and is implemented by all integer
types. It offers bit manipulation, instantiation from literal, and convenient
constants.
Required Associated Constants§
Required Methods§
fn ZERO() -> Self
fn ONE() -> Self
fn TWO() -> Self
Sourcefn from_literal(val: u128) -> Self
fn from_literal(val: u128) -> Self
Get an integer with value val
.
Sourcefn from_hex_string(s: &String) -> Self
fn from_hex_string(s: &String) -> Self
Read a hex string (starting with 0x) into an Integer
.
fn get_bit(self, i: usize) -> Self
fn set_bit(self, b: Self, i: usize) -> Self
fn set(self, pos: usize, y: Self, yi: usize) -> Self
fn rotate_left(self, n: usize) -> Self
fn rotate_right(self, n: usize) -> Self
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Integer for i8
impl Integer for i8
Source§fn set_bit(self, b: Self, i: usize) -> Self
fn set_bit(self, b: Self, i: usize) -> Self
Set bit i
of this integer to b
and return the result.
Bit b
has to be 0
or 1
.
Source§fn set(self, pos: usize, y: Self, yi: usize) -> Self
fn set(self, pos: usize, y: Self, yi: usize) -> Self
Set bit pos
of this integer to bit yi
of integer y
.
const NUM_BITS: usize = 8usize
fn ZERO() -> Self
fn ONE() -> Self
fn TWO() -> Self
fn from_literal(val: u128) -> Self
fn from_hex_string(s: &String) -> Self
fn rotate_left(self, n: usize) -> Self
fn rotate_right(self, n: usize) -> Self
Source§impl Integer for i16
impl Integer for i16
Source§fn set_bit(self, b: Self, i: usize) -> Self
fn set_bit(self, b: Self, i: usize) -> Self
Set bit i
of this integer to b
and return the result.
Bit b
has to be 0
or 1
.
Source§fn set(self, pos: usize, y: Self, yi: usize) -> Self
fn set(self, pos: usize, y: Self, yi: usize) -> Self
Set bit pos
of this integer to bit yi
of integer y
.
const NUM_BITS: usize = 16usize
fn ZERO() -> Self
fn ONE() -> Self
fn TWO() -> Self
fn from_literal(val: u128) -> Self
fn from_hex_string(s: &String) -> Self
fn rotate_left(self, n: usize) -> Self
fn rotate_right(self, n: usize) -> Self
Source§impl Integer for i32
impl Integer for i32
Source§fn set_bit(self, b: Self, i: usize) -> Self
fn set_bit(self, b: Self, i: usize) -> Self
Set bit i
of this integer to b
and return the result.
Bit b
has to be 0
or 1
.
Source§fn set(self, pos: usize, y: Self, yi: usize) -> Self
fn set(self, pos: usize, y: Self, yi: usize) -> Self
Set bit pos
of this integer to bit yi
of integer y
.
const NUM_BITS: usize = 32usize
fn ZERO() -> Self
fn ONE() -> Self
fn TWO() -> Self
fn from_literal(val: u128) -> Self
fn from_hex_string(s: &String) -> Self
fn rotate_left(self, n: usize) -> Self
fn rotate_right(self, n: usize) -> Self
Source§impl Integer for i64
impl Integer for i64
Source§fn set_bit(self, b: Self, i: usize) -> Self
fn set_bit(self, b: Self, i: usize) -> Self
Set bit i
of this integer to b
and return the result.
Bit b
has to be 0
or 1
.
Source§fn set(self, pos: usize, y: Self, yi: usize) -> Self
fn set(self, pos: usize, y: Self, yi: usize) -> Self
Set bit pos
of this integer to bit yi
of integer y
.
const NUM_BITS: usize = 64usize
fn ZERO() -> Self
fn ONE() -> Self
fn TWO() -> Self
fn from_literal(val: u128) -> Self
fn from_hex_string(s: &String) -> Self
fn rotate_left(self, n: usize) -> Self
fn rotate_right(self, n: usize) -> Self
Source§impl Integer for i128
impl Integer for i128
Source§fn set_bit(self, b: Self, i: usize) -> Self
fn set_bit(self, b: Self, i: usize) -> Self
Set bit i
of this integer to b
and return the result.
Bit b
has to be 0
or 1
.
Source§fn set(self, pos: usize, y: Self, yi: usize) -> Self
fn set(self, pos: usize, y: Self, yi: usize) -> Self
Set bit pos
of this integer to bit yi
of integer y
.
const NUM_BITS: usize = 128usize
fn ZERO() -> Self
fn ONE() -> Self
fn TWO() -> Self
fn from_literal(val: u128) -> Self
fn from_hex_string(s: &String) -> Self
fn rotate_left(self, n: usize) -> Self
fn rotate_right(self, n: usize) -> Self
Source§impl Integer for u8
impl Integer for u8
Source§fn set_bit(self, b: Self, i: usize) -> Self
fn set_bit(self, b: Self, i: usize) -> Self
Set bit i
of this integer to b
and return the result.
Bit b
has to be 0
or 1
.
Source§fn set(self, pos: usize, y: Self, yi: usize) -> Self
fn set(self, pos: usize, y: Self, yi: usize) -> Self
Set bit pos
of this integer to bit yi
of integer y
.
const NUM_BITS: usize = 8usize
fn ZERO() -> Self
fn ONE() -> Self
fn TWO() -> Self
fn from_literal(val: u128) -> Self
fn from_hex_string(s: &String) -> Self
fn rotate_left(self, n: usize) -> Self
fn rotate_right(self, n: usize) -> Self
Source§impl Integer for u16
impl Integer for u16
Source§fn set_bit(self, b: Self, i: usize) -> Self
fn set_bit(self, b: Self, i: usize) -> Self
Set bit i
of this integer to b
and return the result.
Bit b
has to be 0
or 1
.
Source§fn set(self, pos: usize, y: Self, yi: usize) -> Self
fn set(self, pos: usize, y: Self, yi: usize) -> Self
Set bit pos
of this integer to bit yi
of integer y
.
const NUM_BITS: usize = 16usize
fn ZERO() -> Self
fn ONE() -> Self
fn TWO() -> Self
fn from_literal(val: u128) -> Self
fn from_hex_string(s: &String) -> Self
fn rotate_left(self, n: usize) -> Self
fn rotate_right(self, n: usize) -> Self
Source§impl Integer for u32
impl Integer for u32
Source§fn set_bit(self, b: Self, i: usize) -> Self
fn set_bit(self, b: Self, i: usize) -> Self
Set bit i
of this integer to b
and return the result.
Bit b
has to be 0
or 1
.
Source§fn set(self, pos: usize, y: Self, yi: usize) -> Self
fn set(self, pos: usize, y: Self, yi: usize) -> Self
Set bit pos
of this integer to bit yi
of integer y
.
const NUM_BITS: usize = 32usize
fn ZERO() -> Self
fn ONE() -> Self
fn TWO() -> Self
fn from_literal(val: u128) -> Self
fn from_hex_string(s: &String) -> Self
fn rotate_left(self, n: usize) -> Self
fn rotate_right(self, n: usize) -> Self
Source§impl Integer for u64
impl Integer for u64
Source§fn set_bit(self, b: Self, i: usize) -> Self
fn set_bit(self, b: Self, i: usize) -> Self
Set bit i
of this integer to b
and return the result.
Bit b
has to be 0
or 1
.
Source§fn set(self, pos: usize, y: Self, yi: usize) -> Self
fn set(self, pos: usize, y: Self, yi: usize) -> Self
Set bit pos
of this integer to bit yi
of integer y
.
const NUM_BITS: usize = 64usize
fn ZERO() -> Self
fn ONE() -> Self
fn TWO() -> Self
fn from_literal(val: u128) -> Self
fn from_hex_string(s: &String) -> Self
fn rotate_left(self, n: usize) -> Self
fn rotate_right(self, n: usize) -> Self
Source§impl Integer for u128
impl Integer for u128
Source§fn set_bit(self, b: Self, i: usize) -> Self
fn set_bit(self, b: Self, i: usize) -> Self
Set bit i
of this integer to b
and return the result.
Bit b
has to be 0
or 1
.
Source§fn set(self, pos: usize, y: Self, yi: usize) -> Self
fn set(self, pos: usize, y: Self, yi: usize) -> Self
Set bit pos
of this integer to bit yi
of integer y
.