pub struct AccountId(/* private fields */);
Expand description
Utility Account Identifier.
This is a unique, syntactically valid, human-readable account identifier on the Utility network.
See the crate-level docs for information about validation.
Also see Error kind precedence.
§Examples
use unc_account_id::AccountId;
let alice: AccountId = "alice.unc".parse().unwrap();
assert!("ƒelicia.unc".parse::<AccountId>().is_err()); // (ƒ is not f)
Implementations§
Source§impl AccountId
impl AccountId
Sourcepub fn validate(account_id: &str) -> Result<(), ParseAccountError>
pub fn validate(account_id: &str) -> Result<(), ParseAccountError>
Validates a string as a well-structured Utility Account ID.
Checks Account ID validity without constructing an AccountId
instance.
§Examples
use unc_account_id::{AccountId, ParseErrorKind};
assert!(AccountId::validate("alice.unc").is_ok());
assert!(
matches!(
AccountId::validate("ƒelicia.unc"), // fancy ƒ!
Err(err) if err.kind() == &ParseErrorKind::InvalidChar
)
);
§Error kind precedence
If an Account ID has multiple format violations, the first one would be reported.
§Examples
use unc_account_id::{AccountId, ParseErrorKind};
assert!(
matches!(
AccountId::validate("A__ƒƒluent."),
Err(err) if err.kind() == &ParseErrorKind::InvalidChar
)
);
assert!(
matches!(
AccountId::validate("a__ƒƒluent."),
Err(err) if err.kind() == &ParseErrorKind::RedundantSeparator
)
);
assert!(
matches!(
AccountId::validate("aƒƒluent."),
Err(err) if err.kind() == &ParseErrorKind::InvalidChar
)
);
assert!(
matches!(
AccountId::validate("affluent."),
Err(err) if err.kind() == &ParseErrorKind::RedundantSeparator
)
);
Methods from Deref<Target = AccountIdRef>§
pub const MIN_LEN: usize = 2usize
pub const MAX_LEN: usize = 64usize
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());