Struct unc_sdk::AccountIdRef
source · pub struct AccountIdRef(/* private fields */);Expand description
Account identifier. This is the human readable UTF-8 string which is used internally to index accounts on the network and their respective state.
This is the “referenced” version of the account ID. It is to AccountId what str is to String,
and works quite similarly to Path. Like with str and Path, you
can’t have a value of type AccountIdRef, but you can have a reference like &AccountIdRef or
&mut AccountIdRef.
This type supports zero-copy deserialization offered by serde, but cannot
do the same for borsh since the latter does not support zero-copy.
§Examples
use unc_account_id::{AccountId, AccountIdRef};
use std::convert::{TryFrom, TryInto};
// Construction
let alice = AccountIdRef::new("alice.unc").unwrap();
assert!(AccountIdRef::new("invalid.").is_err());Implementations§
source§impl AccountIdRef
impl AccountIdRef
sourcepub fn new<S>(id: &S) -> Result<&AccountIdRef, ParseAccountError>
pub fn new<S>(id: &S) -> Result<&AccountIdRef, ParseAccountError>
Construct a &AccountIdRef from a string reference.
This constructor validates the provided ID, and will produce an error when validation fails.
sourcepub const fn new_or_panic(id: &str) -> &AccountIdRef
pub const fn new_or_panic(id: &str) -> &AccountIdRef
Construct a &AccountIdRef from with validation at compile time.
This constructor will panic if validation fails.
use unc_account_id::AccountIdRef;
const ALICE: &AccountIdRef = AccountIdRef::new_or_panic("alice.unc");sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns a string slice of the entire Account ID.
§Examples
use unc_account_id::AccountIdRef;
let carol = AccountIdRef::new("carol.unc").unwrap();
assert_eq!("carol.unc", carol.as_str());sourcepub fn get_account_type(&self) -> AccountType
pub fn get_account_type(&self) -> AccountType
Returns AccountType::EthAccount if the AccountId is a 40 characters long hexadecimal prefixed with ‘0x’.
Returns AccountType::Un cImplicitAccount if the AccountId is a 64 characters long hexadecimal.
Otherwise, returns AccountType::Reserved.
See Implicit-Accounts.
§Examples
use unc_account_id::{AccountId, AccountType};
let alice: AccountId = "alice.unc".parse().unwrap();
assert!(alice.get_account_type() == AccountType::Reserved);
let eth_rando = "0xb794f5ea0ba39494ce839613fffba74279579268"
.parse::<AccountId>()
.unwrap();
assert!(eth_rando.get_account_type() == AccountType::EthAccount);
let unc_rando = "98793cd91a3f870fb126f66285808c7e094afcfc4eda8a970f6648cdf0dbd6de"
.parse::<AccountId>()
.unwrap();
assert!(unc_rando.get_account_type() == AccountType::UtilityAccount);sourcepub fn is_system(&self) -> bool
pub fn is_system(&self) -> bool
Returns true if this AccountId is the system account.
See System account.
§Examples
use unc_account_id::AccountId;
let alice: AccountId = "alice.unc".parse().unwrap();
assert!(!alice.is_system());
let system: AccountId = "system".parse().unwrap();
assert!(system.is_system());sourcepub fn get_parent_account_id(&self) -> Option<&AccountIdRef>
pub fn get_parent_account_id(&self) -> Option<&AccountIdRef>
Returns parent’s account id reference
§Examples
use unc_account_id::{AccountIdRef, AccountType};
let unc: &AccountIdRef = AccountIdRef::new_or_panic("unc");
assert!(unc.get_parent_account_id().is_none());
let implicit: &AccountIdRef = AccountIdRef::new_or_panic("248e104d1d4764d713c4211c13808c8fc887869c580f4178e60538ac5c2a0b26");
assert!(implicit.get_parent_account_id().is_none());Trait Implementations§
source§impl AsRef<AccountIdRef> for AccountId
impl AsRef<AccountIdRef> for AccountId
source§fn as_ref(&self) -> &AccountIdRef
fn as_ref(&self) -> &AccountIdRef
source§impl AsRef<str> for AccountIdRef
impl AsRef<str> for AccountIdRef
source§impl Borrow<AccountIdRef> for AccountId
impl Borrow<AccountIdRef> for AccountId
source§fn borrow(&self) -> &AccountIdRef
fn borrow(&self) -> &AccountIdRef
source§impl BorshSerialize for AccountIdRef
impl BorshSerialize for AccountIdRef
source§impl Debug for AccountIdRef
impl Debug for AccountIdRef
source§impl<'de> Deserialize<'de> for &'de AccountIdRef
impl<'de> Deserialize<'de> for &'de AccountIdRef
source§fn deserialize<D>(
deserializer: D
) -> Result<&'de AccountIdRef, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<&'de AccountIdRef, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
source§impl Display for AccountIdRef
impl Display for AccountIdRef
source§impl<'a> From<&'a AccountIdRef> for AccountId
impl<'a> From<&'a AccountIdRef> for AccountId
source§fn from(id: &'a AccountIdRef) -> AccountId
fn from(id: &'a AccountIdRef) -> AccountId
source§impl Hash for AccountIdRef
impl Hash for AccountIdRef
source§impl Ord for AccountIdRef
impl Ord for AccountIdRef
source§impl<'a> PartialEq<&'a AccountIdRef> for AccountId
impl<'a> PartialEq<&'a AccountIdRef> for AccountId
source§fn eq(&self, other: &&'a AccountIdRef) -> bool
fn eq(&self, other: &&'a AccountIdRef) -> bool
self and other values to be equal, and is used
by ==.source§impl<'a> PartialEq<&'a AccountIdRef> for str
impl<'a> PartialEq<&'a AccountIdRef> for str
source§fn eq(&self, other: &&'a AccountIdRef) -> bool
fn eq(&self, other: &&'a AccountIdRef) -> bool
self and other values to be equal, and is used
by ==.source§impl<'a> PartialEq<&'a str> for AccountIdRef
impl<'a> PartialEq<&'a str> for AccountIdRef
source§impl<'a> PartialEq<AccountId> for &'a AccountIdRef
impl<'a> PartialEq<AccountId> for &'a AccountIdRef
source§impl PartialEq<AccountId> for AccountIdRef
impl PartialEq<AccountId> for AccountIdRef
source§impl<'a> PartialEq<AccountIdRef> for &'a str
impl<'a> PartialEq<AccountIdRef> for &'a str
source§fn eq(&self, other: &AccountIdRef) -> bool
fn eq(&self, other: &AccountIdRef) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialEq<AccountIdRef> for AccountId
impl PartialEq<AccountIdRef> for AccountId
source§fn eq(&self, other: &AccountIdRef) -> bool
fn eq(&self, other: &AccountIdRef) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialEq<AccountIdRef> for str
impl PartialEq<AccountIdRef> for str
source§fn eq(&self, other: &AccountIdRef) -> bool
fn eq(&self, other: &AccountIdRef) -> bool
self and other values to be equal, and is used
by ==.source§impl<'a> PartialEq<String> for &'a AccountIdRef
impl<'a> PartialEq<String> for &'a AccountIdRef
source§impl PartialEq<String> for AccountIdRef
impl PartialEq<String> for AccountIdRef
source§impl<'a> PartialEq<str> for &'a AccountIdRef
impl<'a> PartialEq<str> for &'a AccountIdRef
source§impl PartialEq<str> for AccountIdRef
impl PartialEq<str> for AccountIdRef
source§impl PartialEq for AccountIdRef
impl PartialEq for AccountIdRef
source§fn eq(&self, other: &AccountIdRef) -> bool
fn eq(&self, other: &AccountIdRef) -> bool
self and other values to be equal, and is used
by ==.source§impl<'a> PartialOrd<&'a AccountIdRef> for AccountId
impl<'a> PartialOrd<&'a AccountIdRef> for AccountId
source§fn partial_cmp(&self, other: &&'a AccountIdRef) -> Option<Ordering>
fn partial_cmp(&self, other: &&'a AccountIdRef) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<&'a AccountIdRef> for str
impl<'a> PartialOrd<&'a AccountIdRef> for str
source§fn partial_cmp(&self, other: &&'a AccountIdRef) -> Option<Ordering>
fn partial_cmp(&self, other: &&'a AccountIdRef) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<&'a str> for AccountIdRef
impl<'a> PartialOrd<&'a str> for AccountIdRef
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<AccountId> for &'a AccountIdRef
impl<'a> PartialOrd<AccountId> for &'a AccountIdRef
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<AccountId> for AccountIdRef
impl PartialOrd<AccountId> for AccountIdRef
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<AccountIdRef> for &'a str
impl<'a> PartialOrd<AccountIdRef> for &'a str
source§fn partial_cmp(&self, other: &AccountIdRef) -> Option<Ordering>
fn partial_cmp(&self, other: &AccountIdRef) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<AccountIdRef> for AccountId
impl PartialOrd<AccountIdRef> for AccountId
source§fn partial_cmp(&self, other: &AccountIdRef) -> Option<Ordering>
fn partial_cmp(&self, other: &AccountIdRef) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<AccountIdRef> for str
impl PartialOrd<AccountIdRef> for str
source§fn partial_cmp(&self, other: &AccountIdRef) -> Option<Ordering>
fn partial_cmp(&self, other: &AccountIdRef) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<String> for &'a AccountIdRef
impl<'a> PartialOrd<String> for &'a AccountIdRef
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<String> for AccountIdRef
impl PartialOrd<String> for AccountIdRef
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> PartialOrd<str> for &'a AccountIdRef
impl<'a> PartialOrd<str> for &'a AccountIdRef
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd<str> for AccountIdRef
impl PartialOrd<str> for AccountIdRef
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl PartialOrd for AccountIdRef
impl PartialOrd for AccountIdRef
source§fn partial_cmp(&self, other: &AccountIdRef) -> Option<Ordering>
fn partial_cmp(&self, other: &AccountIdRef) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more