pub struct Scalar {
    bytes: Bytes,
}
Expand description

The Scalar type used in cryptographic operations.

Fields

bytes: Bytes

Implementations

pub fn new() -> Self

Returns a new, uninitialized Scalar.

Returns

  • [Scalar] - The new Scalar.

Examples

use std::scalar::Scalar;

fn foo() {
    let new_scalar = Scalar::new();
}

pub fn zero() -> Self

Returns a zeroed Scalar.

Returns

  • [Scalar] - The new zeroed Scalar.

Examples

use std::scalar::Scalar;

fn foo() {
    let zero_scalar = Scalar::zero();
    assert(b256::try_from(new_scalar.bytes()).unwrap() == b256::zero());
}

pub fn min() -> Self

Returns the minimum scalar.

Returns

  • [Scalar] - The new minimum Scalar.

Examples

use std::scalar::Scalar;

fn foo() {
    let zero_scalar = Scalar::zero();
    assert(b256::try_from(new_scalar.bytes()).unwrap() == b256::zero());
}

pub fn is_zero(self) -> bool

Returns true if the scalar is zero, otherwise false.

Returns

Examples

use std::scalar::Scalar;

fn foo() {
    let zero_scalar = Scalar::zero();
    assert(zero_scalar.is_zero());
}

pub fn bytes(self) -> Bytes

Returns the underlying bytes of the scalar.

Returns

  • [Bytes] - The scalar represented as bytes.

Examples

use std::scalar::Scalar;

fn foo(scalar: Scalar) {
    let bytes = scalar.bytes();
    assert(bytes.len() != 0);
}

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(bytes: u256) -> Self

pub fn from(bytes: b256) -> Self

pub fn from(bytes_array: [u8; 32]) -> Self