Struct std::b512::B512

pub struct B512 {
    /// The two `b256`s that make up the `B512`.
    bits: [b256; 2],
}
Expand description

Stores two b256s in contiguous memory.
Guaranteed to be contiguous for use with ec-recover: std::ecr::ec_recover.

Fields

bits: [b256; 2]

The two b256s that make up the B512.

Implementations

pub fn new() -> Self

Initializes a new, zeroed B512.

Returns

  • [B512] - A zero value B512.

Examples

use std::b512::B512;

fn foo() {
    let zero = B512::new();
}

pub fn bits(self) -> [b256; 2]

Returns the underlying bits for the B512 type.

Returns

  • [[b256; 2]] - The two b256s that make up the B512.

Examples

use std::b512::B512;

fn foo() {
    let zero = B512::new();
    assert(zero.bits() == [b256::zero(), b256::zero()]);
}

pub fn zero() -> Self

Returns the zero value for the B512 type.

Returns

  • [B512] -> The zero value for the B512 type.

Examples

use std::b512::B512;

fn foo() {
    let zero_b512 = B512::zero();
    assert(zero_b512 == B512::from((b256::zero(), b256::zero())));
}

pub fn is_zero(self) -> bool

Returns whether a B512 is set to zero.

Returns

  • [bool] -> True if the B512 is zero, otherwise false.

Examples

use std::b512::B512;

fn foo() {
    let zero_b512 = B512::zero();
    assert(zero_b512.is_zero());
}

Trait Implementations

pub fn abi_encode(self, buffer: Buffer) -> Buffer

pub fn abi_decode(refmut buffer: BufferReader) -> Self

pub fn eq(self, other: Self) -> bool

pub fn neq(self, other: Self) -> bool

Evaluates if two values of the same type are not equal.

Additional Information

This function is inherited when eq() is implemented.

Arguments

  • other: [Self] - The value of the same type.

Returns

  • [bool] - true if the two values are not equal, otherwise false.

Examples

struct MyStruct {
    val: u64,
}

impl Eq for MyStruct {
    fn eq(self, other: Self) -> bool {
         self.val == other.val
    }
}

fn foo() {
    let struct1 = MyStruct { val: 10 };
    let struct2 = MyStruct { val: 2 };
    let result = struct1 != struct2;
    assert(result);
}

pub fn from(components: (b256, b256)) -> Self

Converts from a b256 tuple to a B512.

Arguments

  • components: [(b256, b256)] - The (b256, b256) tuple to convert to a B512.

Returns

  • [B512] - The newly created B512.

Examples

use std::b512::B512;

fn foo() {
    let tuple: (b256, b256) = (b256::zero(), b256::zero());
    let b512 = B512::from(tuple);
}

pub fn try_from(bytes: Bytes) -> Option<Self>

Casts raw Bytes data to an B512.

Arguments

  • bytes: [Bytes] - The raw Bytes data to be casted.

Returns

  • [B512] - The newly created B512 from the raw Bytes.

Examples

use std::bytes::Bytes;

fn foo(bytes: Bytes) {
   let result = B512::try_from(bytes);
   assert(result.is_some());
   let b512 = result.unwrap();
}

pub fn into(self) -> Bytes

Casts an B512 to raw Bytes data.

Returns

  • [Bytes] - The underlying raw Bytes data of the B512.

Examples

fn foo() {
    let b512 = B512::from((b256::zero(), b256::zero()));
    let bytes_data: Bytes = b512.into()
    assert(bytes_data.len() == 64);
}