hacspec_lib::prelude

Trait Integer

Source
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§

Source

fn ZERO() -> Self

Source

fn ONE() -> Self

Source

fn TWO() -> Self

Source

fn from_literal(val: u128) -> Self

Get an integer with value val.

Source

fn from_hex_string(s: &String) -> Self

Read a hex string (starting with 0x) into an Integer.

Source

fn get_bit(self, i: usize) -> Self

Source

fn set_bit(self, b: Self, i: usize) -> Self

Source

fn set(self, pos: usize, y: Self, yi: usize) -> Self

Source

fn rotate_left(self, n: usize) -> Self

Source

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

Source§

fn get_bit(self, i: usize) -> Self

Get bit i of this integer.

Source§

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

Set bit pos of this integer to bit yi of integer y.

Source§

const NUM_BITS: usize = 8usize

Source§

fn ZERO() -> Self

Source§

fn ONE() -> Self

Source§

fn TWO() -> Self

Source§

fn from_literal(val: u128) -> Self

Source§

fn from_hex_string(s: &String) -> Self

Source§

fn rotate_left(self, n: usize) -> Self

Source§

fn rotate_right(self, n: usize) -> Self

Source§

impl Integer for i16

Source§

fn get_bit(self, i: usize) -> Self

Get bit i of this integer.

Source§

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

Set bit pos of this integer to bit yi of integer y.

Source§

const NUM_BITS: usize = 16usize

Source§

fn ZERO() -> Self

Source§

fn ONE() -> Self

Source§

fn TWO() -> Self

Source§

fn from_literal(val: u128) -> Self

Source§

fn from_hex_string(s: &String) -> Self

Source§

fn rotate_left(self, n: usize) -> Self

Source§

fn rotate_right(self, n: usize) -> Self

Source§

impl Integer for i32

Source§

fn get_bit(self, i: usize) -> Self

Get bit i of this integer.

Source§

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

Set bit pos of this integer to bit yi of integer y.

Source§

const NUM_BITS: usize = 32usize

Source§

fn ZERO() -> Self

Source§

fn ONE() -> Self

Source§

fn TWO() -> Self

Source§

fn from_literal(val: u128) -> Self

Source§

fn from_hex_string(s: &String) -> Self

Source§

fn rotate_left(self, n: usize) -> Self

Source§

fn rotate_right(self, n: usize) -> Self

Source§

impl Integer for i64

Source§

fn get_bit(self, i: usize) -> Self

Get bit i of this integer.

Source§

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

Set bit pos of this integer to bit yi of integer y.

Source§

const NUM_BITS: usize = 64usize

Source§

fn ZERO() -> Self

Source§

fn ONE() -> Self

Source§

fn TWO() -> Self

Source§

fn from_literal(val: u128) -> Self

Source§

fn from_hex_string(s: &String) -> Self

Source§

fn rotate_left(self, n: usize) -> Self

Source§

fn rotate_right(self, n: usize) -> Self

Source§

impl Integer for i128

Source§

fn get_bit(self, i: usize) -> Self

Get bit i of this integer.

Source§

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

Set bit pos of this integer to bit yi of integer y.

Source§

const NUM_BITS: usize = 128usize

Source§

fn ZERO() -> Self

Source§

fn ONE() -> Self

Source§

fn TWO() -> Self

Source§

fn from_literal(val: u128) -> Self

Source§

fn from_hex_string(s: &String) -> Self

Source§

fn rotate_left(self, n: usize) -> Self

Source§

fn rotate_right(self, n: usize) -> Self

Source§

impl Integer for u8

Source§

fn get_bit(self, i: usize) -> Self

Get bit i of this integer.

Source§

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

Set bit pos of this integer to bit yi of integer y.

Source§

const NUM_BITS: usize = 8usize

Source§

fn ZERO() -> Self

Source§

fn ONE() -> Self

Source§

fn TWO() -> Self

Source§

fn from_literal(val: u128) -> Self

Source§

fn from_hex_string(s: &String) -> Self

Source§

fn rotate_left(self, n: usize) -> Self

Source§

fn rotate_right(self, n: usize) -> Self

Source§

impl Integer for u16

Source§

fn get_bit(self, i: usize) -> Self

Get bit i of this integer.

Source§

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

Set bit pos of this integer to bit yi of integer y.

Source§

const NUM_BITS: usize = 16usize

Source§

fn ZERO() -> Self

Source§

fn ONE() -> Self

Source§

fn TWO() -> Self

Source§

fn from_literal(val: u128) -> Self

Source§

fn from_hex_string(s: &String) -> Self

Source§

fn rotate_left(self, n: usize) -> Self

Source§

fn rotate_right(self, n: usize) -> Self

Source§

impl Integer for u32

Source§

fn get_bit(self, i: usize) -> Self

Get bit i of this integer.

Source§

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

Set bit pos of this integer to bit yi of integer y.

Source§

const NUM_BITS: usize = 32usize

Source§

fn ZERO() -> Self

Source§

fn ONE() -> Self

Source§

fn TWO() -> Self

Source§

fn from_literal(val: u128) -> Self

Source§

fn from_hex_string(s: &String) -> Self

Source§

fn rotate_left(self, n: usize) -> Self

Source§

fn rotate_right(self, n: usize) -> Self

Source§

impl Integer for u64

Source§

fn get_bit(self, i: usize) -> Self

Get bit i of this integer.

Source§

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

Set bit pos of this integer to bit yi of integer y.

Source§

const NUM_BITS: usize = 64usize

Source§

fn ZERO() -> Self

Source§

fn ONE() -> Self

Source§

fn TWO() -> Self

Source§

fn from_literal(val: u128) -> Self

Source§

fn from_hex_string(s: &String) -> Self

Source§

fn rotate_left(self, n: usize) -> Self

Source§

fn rotate_right(self, n: usize) -> Self

Source§

impl Integer for u128

Source§

fn get_bit(self, i: usize) -> Self

Get bit i of this integer.

Source§

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

Set bit pos of this integer to bit yi of integer y.

Source§

const NUM_BITS: usize = 128usize

Source§

fn ZERO() -> Self

Source§

fn ONE() -> Self

Source§

fn TWO() -> Self

Source§

fn from_literal(val: u128) -> Self

Source§

fn from_hex_string(s: &String) -> Self

Source§

fn rotate_left(self, n: usize) -> Self

Source§

fn rotate_right(self, n: usize) -> Self

Implementors§

Source§

impl Integer for BigInt

Source§

const NUM_BITS: usize = 0usize

Source§

impl Integer for I8

Source§

const NUM_BITS: usize = 8usize

Source§

impl Integer for I16

Source§

const NUM_BITS: usize = 16usize

Source§

impl Integer for I32

Source§

const NUM_BITS: usize = 32usize

Source§

impl Integer for I64

Source§

const NUM_BITS: usize = 64usize

Source§

impl Integer for I128

Source§

const NUM_BITS: usize = 128usize

Source§

impl Integer for U8

Source§

const NUM_BITS: usize = 8usize

Source§

impl Integer for U16

Source§

const NUM_BITS: usize = 16usize

Source§

impl Integer for U32

Source§

const NUM_BITS: usize = 32usize

Source§

impl Integer for U64

Source§

const NUM_BITS: usize = 64usize

Source§

impl Integer for U128

Source§

const NUM_BITS: usize = 128usize