pub struct Principal { /* private fields */ }Expand description
An opaque IC identity containing at most 29 significant bytes.
Ordering compares length first, then bytes. Binary Serde includes only the significant bytes; human-readable Serde uses canonical Principal text. Deserialization accepts string or byte callbacks, but not numeric sequences.
Implementations§
Source§impl Principal
impl Principal
Sourcepub const MAX_LENGTH_IN_BYTES: usize = 29
pub const MAX_LENGTH_IN_BYTES: usize = 29
The maximum significant binary length.
Sourcepub const MAX_LENGTH_IN_TEXT: usize = 63
pub const MAX_LENGTH_IN_TEXT: usize = 63
The maximum admitted UTF-8 byte length of Principal text.
Sourcepub const fn management_canister() -> Principal
pub const fn management_canister() -> Principal
Returns the zero-byte management canister identity.
Sourcepub const fn anonymous() -> Principal
pub const fn anonymous() -> Principal
Returns the one-byte anonymous identity, whose byte is 4.
Sourcepub const fn from_slice(slice: &[u8]) -> Principal
pub const fn from_slice(slice: &[u8]) -> Principal
Sourcepub const fn try_from_slice(slice: &[u8]) -> Result<Principal, PrincipalError>
pub const fn try_from_slice(slice: &[u8]) -> Result<Principal, PrincipalError>
Copies bytes, returning PrincipalError::BytesTooLong above 29 bytes.
Sourcepub fn from_text<S>(text: S) -> Result<Principal, PrincipalError>
pub fn from_text<S>(text: S) -> Result<Principal, PrincipalError>
Parses bounded, checksummed Base32 text with canonical dash grouping.
ASCII case differences are accepted. Inputs longer than 63 bytes are refused before decoding. Whitespace and padding are not accepted.
Sourcepub fn to_text(&self) -> String
pub fn to_text(&self) -> String
Returns lowercase canonical text with a dash after every five digits.
Sourcepub const fn len(&self) -> u8
pub const fn len(&self) -> u8
Returns the significant byte length; zero identifies the management canister.
Sourcepub const fn as_fixed_bytes(&self) -> &[u8; 29]
pub const fn as_fixed_bytes(&self) -> &[u8; 29]
Borrows the fixed storage, whose tail after Self::len is zero.
Sourcepub fn write_text<'a>(&self, output: &'a mut [u8; 63]) -> &'a str
pub fn write_text<'a>(&self, output: &'a mut [u8; 63]) -> &'a str
Write canonical Principal text into caller-owned storage without allocation.
The returned string borrows the supplied buffer. No identity authority or normalization beyond canonical text formatting is implied.
§Panics
Panics if the Base32 supplier violates its ASCII output contract.