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>
fn as_address(self) -> Option<Address>
Returns the Address
of the Identity
.
Returns
- [Option] -
Some(Address)
if the underlying type is anAddress
, otherwiseNone
.
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>
fn as_contract_id(self) -> Option<ContractId>
Returns the ContractId
of the Identity
.
Returns
- [Option] -
Some(Contract)
if the underlying type is anContractId
, otherwiseNone
.
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
fn is_address(self) -> bool
Returns whether the Identity
represents an Address
.
Returns
- [bool] - Indicates whether the
Identity
holds anAddress
.
Examples
fn foo() {
let identity = Identity::Address(Address::zero());
assert(identity.is_address());
}
fn is_contract_id(self) -> bool
fn is_contract_id(self) -> bool
Returns whether the Identity
represents a ContractId
.
Returns
- [bool] - Indicates whether the
Identity
holds aContractId
.
Examples
fn foo() {
let identity = Identity::ContractId(ContractId::zero());
assert(identity.is_contract_id());
}
fn bits(self) -> b256
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
impl AbiEncode for Identity
impl AbiEncode for Identity
fn abi_encode(self, buffer: Buffer) -> Buffer
impl AbiDecode for Identity
impl AbiDecode for Identity
fn abi_decode(refmut buffer: BufferReader) -> Self
impl Eq for Identity
impl Eq for Identity
fn eq(self, other: Self) -> bool
fn neq(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, otherwisefalse
.
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);
}