pub enum Identity {
    Address: Address,
    ContractId: ContractId,
}
Expand description

The Identity type: either an Address or a ContractId.

Variants

Address: Address

ContractId: ContractId

Implementations

fn as_address(self) -> Option<Address>

Returns the Address of the Identity.

Returns

  • [Option] - Some(Address) if the underlying type is an Address, otherwise None.

Examples

use std::constants::ZERO_B256;

fn foo() {
    let identity = Identity::Address(Address::from(ZERO_B256));
    let address = identity.as_address();
    assert(address == Address::from(ZERO_B256));
}

fn as_contract_id(self) -> Option<ContractId>

Returns the ContractId of the Identity.

Returns

  • [Option] - Some(Contract) if the underlying type is an ContractId, otherwise None.

Examples

use std::constants::ZERO_B256;

fn foo() {
    let identity = Identity::ContractId(ContractId::from(ZERO_B256));
    let contract_id = identity.as_contract_id();
    assert(contract_id == ContractId::from(ZERO_B256));
}

fn is_address(self) -> bool

Returns whether the Identity represents an Address.

Returns

  • [bool] - Indicates whether the Identity holds an Address.

Examples

use std::constants::ZERO_B256;

fn foo() {
    let identity = Identity::Address(Address::from(ZERO_B256));
    assert(identity.is_address());
}

fn is_contract_id(self) -> bool

Returns whether the Identity represents a ContractId.

Returns

  • [bool] - Indicates whether the Identity holds a ContractId.

Examples

use std::constants::ZERO_B256;

fn foo() {
    let identity = Identity::ContractId(ContractId::from(ZERO_B256));
    assert(identity.is_contract_id());
}

fn bits(self) -> b256

Returns the underlying raw b256 data of the identity.

Returns

  • [b256] - The raw data of the identity.

Examples

use std::constants::ZERO_B256;

fn foo() -> {
    let my_identity = Identity::Address(Address::from(ZERO_B256));
    assert(my_identity.bits() == ZERO_B256);
}

Trait Implementations

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

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);
}

fn hash(
self,
refmut state: Hasher,
)