miden_objects/address/interface.rs
1use crate::AddressError;
2
3/// The account interface of an [`Address`](super::Address).
4///
5/// An interface specifies the set of procedures of an account, which determines which notes it is
6/// able to receive and consume.
7///
8/// The enum is non-exhaustive so it can be extended in the future without it being a breaking
9/// change. Users are expected to match on the variants that they are able to handle and ignore the
10/// remaining ones.
11///
12/// ## Guarantees
13///
14/// An interface encodes to a `u16`, but is guaranteed to take up at most 11 of its bits. This
15/// constraint allows encoding the interface into an address efficiently.
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
17#[repr(u16)]
18#[non_exhaustive]
19pub enum AddressInterface {
20 /// The basic wallet interface.
21 BasicWallet = Self::BASIC_WALLET,
22}
23
24impl AddressInterface {
25 // Constants for internal use only.
26 const BASIC_WALLET: u16 = 0;
27}
28
29impl TryFrom<u16> for AddressInterface {
30 type Error = AddressError;
31
32 /// Decodes an [`AddressInterface`] from its bytes representation.
33 fn try_from(value: u16) -> Result<Self, Self::Error> {
34 match value {
35 Self::BASIC_WALLET => Ok(Self::BasicWallet),
36 other => Err(AddressError::UnknownAddressInterface(other)),
37 }
38 }
39}