Skip to main content

FieldBytes

Trait FieldBytes 

Source
pub trait FieldBytes: Field {
    // Required methods
    fn to_le_bytes(&self) -> Vec<u8> ;
    fn from_le_bytes(bytes: &[u8]) -> Result<Self, Error>;
}
Expand description

Byte serialization for field elements.

Required by proof-system transcripts to absorb and squeeze field elements deterministically.

§Examples

use field_cat::{BabyBear, FieldBytes};

let a = BabyBear::new(123_456);
let bytes = a.to_le_bytes();
let b = BabyBear::from_le_bytes(&bytes)?;
assert_eq!(a, b);

Required Methods§

Source

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

Serialize this element to little-endian bytes.

Source

fn from_le_bytes(bytes: &[u8]) -> Result<Self, Error>

Deserialize from little-endian bytes.

§Errors

Returns Error::InvalidFieldEncoding if the bytes cannot be interpreted as a valid field element of this type.

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.

Implementors§