pub struct AccountId(/* private fields */);Expand description
A NEAR account identifier.
Valid account IDs:
- Named: “alice.near”, “bob.testnet”, “sub.account.near”
- Implicit (64 hex chars): “0123456789abcdef…”
- EVM implicit (0x + 40 hex chars): “0x1234…”
§Examples
use near_kit::AccountId;
let named: AccountId = "alice.testnet".parse().unwrap();
assert!(named.is_named());
let implicit = "0".repeat(64).parse::<AccountId>().unwrap();
assert!(implicit.is_implicit());Implementations§
Source§impl AccountId
impl AccountId
Sourcepub fn new(s: impl Into<String>) -> Result<Self, ParseAccountIdError>
pub fn new(s: impl Into<String>) -> Result<Self, ParseAccountIdError>
Parse and validate an account ID.
Sourcepub fn parse_lenient(s: impl AsRef<str>) -> Self
pub fn parse_lenient(s: impl AsRef<str>) -> Self
Parse an account ID, falling back to unchecked if validation fails.
This is a convenience method for APIs that accept user input where we want to be lenient. If parsing fails, the string is used as-is.
§Example
use near_kit::AccountId;
// Valid account parses normally
let valid = AccountId::parse_lenient("alice.near");
assert_eq!(valid.as_str(), "alice.near");
// Invalid account is used as-is (no error)
let invalid = AccountId::parse_lenient("INVALID");
assert_eq!(invalid.as_str(), "INVALID");Sourcepub fn is_implicit(&self) -> bool
pub fn is_implicit(&self) -> bool
Check if this is an implicit account (64 hex chars).
Sourcepub fn is_evm_implicit(&self) -> bool
pub fn is_evm_implicit(&self) -> bool
Check if this is an EVM implicit account (0x prefix).
Sourcepub fn is_top_level(&self) -> bool
pub fn is_top_level(&self) -> bool
Check if this is a top-level account (no dots, like “near” or “testnet”).
Sourcepub fn is_sub_account_of(&self, parent: &AccountId) -> bool
pub fn is_sub_account_of(&self, parent: &AccountId) -> bool
Check if this is a subaccount of another account.
Trait Implementations§
Source§impl BorshDeserialize for AccountId
impl BorshDeserialize for AccountId
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Deserializes this instance from a given slice of bytes.
Updates the buffer to point at the remaining bytes.
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSerialize for AccountId
impl BorshSerialize for AccountId
Source§impl<'de> Deserialize<'de> for AccountId
impl<'de> Deserialize<'de> for AccountId
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl IntoContractId for &AccountId
impl IntoContractId for &AccountId
Source§impl IntoContractId for AccountId
impl IntoContractId for AccountId
impl Eq for AccountId
impl StructuralPartialEq for AccountId
Auto Trait Implementations§
impl Freeze for AccountId
impl RefUnwindSafe for AccountId
impl Send for AccountId
impl Sync for AccountId
impl Unpin for AccountId
impl UnsafeUnpin for AccountId
impl UnwindSafe for AccountId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.