miden_objects/address/
type.rs

1use crate::AddressError;
2use crate::errors::Bech32Error;
3
4/// The type of an [`Address`](super::Address) in Miden.
5///
6/// The byte values of this address type should be chosen as a multiple of 8. That way, the first
7/// character of the bech32 string after the `1` separator will be different for every address type.
8/// This makes the type of the address conveniently human-readable.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
10#[repr(u8)]
11pub enum AddressType {
12    AccountId = Self::ACCOUNT_ID,
13}
14
15impl AddressType {
16    // Constants for internal use only.
17    const ACCOUNT_ID: u8 = 0;
18}
19
20impl TryFrom<u8> for AddressType {
21    type Error = AddressError;
22
23    /// Decodes an [`AddressType`] from its byte representation.
24    fn try_from(byte: u8) -> Result<Self, Self::Error> {
25        match byte {
26            Self::ACCOUNT_ID => Ok(Self::AccountId),
27            other => Err(AddressError::Bech32DecodeError(Bech32Error::UnknownAddressType(other))),
28        }
29    }
30}