Skip to main content

FieldHelpers

Trait FieldHelpers 

Source
pub trait FieldHelpers<F> {
    // Required methods
    fn from_bytes(bytes: &[u8]) -> Result<F>;
    fn from_hex(hex: &str) -> Result<F>;
    fn from_bits(bits: &[bool]) -> Result<F>;
    fn to_bytes(&self) -> Vec<u8> ;
    fn to_hex(&self) -> String;
    fn to_bits(&self) -> Vec<bool>;
    fn bits_to_field(&self, start: usize, end: usize) -> Result<F>;

    // Provided methods
    fn from_biguint(big: &BigUint) -> Result<F>
       where F: PrimeField { ... }
    fn to_biguint(&self) -> BigUint
       where F: PrimeField { ... }
    fn to_bigint_positive(&self) -> BigInt
       where F: PrimeField { ... }
    fn size_in_bytes() -> usize
       where F: PrimeField { ... }
    fn modulus_biguint() -> BigUint
       where F: PrimeField { ... }
}
Expand description

Field element helpers Unless otherwise stated everything is in little-endian byte order.

Required Methods§

Source

fn from_bytes(bytes: &[u8]) -> Result<F>

Deserialize from bytes

§Errors

Returns error if deserialization fails.

Source

fn from_hex(hex: &str) -> Result<F>

Deserialize from little-endian hex

§Errors

Returns error if hex decoding or deserialization fails.

Source

fn from_bits(bits: &[bool]) -> Result<F>

Deserialize from bits

§Errors

Returns error if deserialization fails.

Source

fn to_bytes(&self) -> Vec<u8>

Serialize to bytes

Source

fn to_hex(&self) -> String

Serialize to hex

Source

fn to_bits(&self) -> Vec<bool>

Serialize to bits

Source

fn bits_to_field(&self, start: usize, end: usize) -> Result<F>

Create a new field element from this field elements bits

§Errors

Returns error if deserialization fails.

Provided Methods§

Source

fn from_biguint(big: &BigUint) -> Result<F>
where F: PrimeField,

Deserialize from BigUint

§Errors

Returns error if conversion fails.

Source

fn to_biguint(&self) -> BigUint
where F: PrimeField,

Serialize field element to a BigUint

Source

fn to_bigint_positive(&self) -> BigInt
where F: PrimeField,

Serialize field element f to a (positive) BigInt directly.

Source

fn size_in_bytes() -> usize
where F: PrimeField,

Field size in bytes

Source

fn modulus_biguint() -> BigUint
where F: PrimeField,

Get the modulus as BigUint

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F: Field> FieldHelpers<F> for F