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

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

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

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

fn is_address(self) -> bool

Returns whether the Identity represents an Address.

Returns

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

Examples

fn foo() {
    let identity = Identity::Address(Address::zero());
    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

fn foo() {
    let identity = Identity::ContractId(ContractId::zero());
    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

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

Trait Implementations

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

fn abi_decode(refmut buffer: BufferReader) -> Self

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,
)