snarkvm_console_types_field/
lib.rs#![cfg_attr(test, allow(clippy::assertions_on_result_states))]
#![warn(clippy::cast_possible_truncation)]
mod arithmetic;
mod bitwise;
mod bytes;
mod compare;
mod from_bits;
mod one;
mod parse;
mod random;
mod serialize;
mod size_in_bits;
mod size_in_bytes;
mod to_bits;
mod zero;
pub use snarkvm_console_network_environment::prelude::*;
pub use snarkvm_console_types_boolean::Boolean;
use zeroize::Zeroize;
#[derive(Copy, Clone, PartialEq, Eq, Hash, Zeroize)]
pub struct Field<E: Environment> {
field: E::Field,
}
impl<E: Environment> FieldTrait for Field<E> {}
impl<E: Environment> Field<E> {
pub const SIZE_IN_BITS: usize = E::Field::SIZE_IN_BITS;
pub const SIZE_IN_BYTES: usize = (E::Field::SIZE_IN_BITS + 7) / 8;
pub const SIZE_IN_DATA_BITS: usize = E::Field::SIZE_IN_DATA_BITS;
pub const fn new(field: E::Field) -> Self {
Self { field }
}
pub fn new_domain_separator(domain: &str) -> Self {
Self::new(E::Field::from_bytes_le_mod_order(domain.as_bytes()))
}
pub fn from_u8(value: u8) -> Self {
Self { field: E::Field::from(value as u128) }
}
pub fn from_u16(value: u16) -> Self {
Self { field: E::Field::from(value as u128) }
}
pub fn from_u32(value: u32) -> Self {
Self { field: E::Field::from(value as u128) }
}
pub fn from_u64(value: u64) -> Self {
Self { field: E::Field::from(value as u128) }
}
pub fn from_u128(value: u128) -> Self {
Self { field: E::Field::from(value) }
}
pub fn half() -> Self {
Self { field: E::Field::half() }
}
}
impl<E: Environment> Default for Field<E> {
fn default() -> Self {
Self::zero()
}
}
impl<E: Environment> TypeName for Field<E> {
#[inline]
fn type_name() -> &'static str {
"field"
}
}
impl<E: Environment> Deref for Field<E> {
type Target = E::Field;
#[inline]
fn deref(&self) -> &Self::Target {
&self.field
}
}
impl<E: Environment> DerefMut for Field<E> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.field
}
}