Skip to main content

miden_protocol/account/component/
code.rs

1use miden_assembly::Library;
2use miden_processor::MastForest;
3
4// ACCOUNT COMPONENT CODE
5// ================================================================================================
6
7/// A [`Library`] that has been assembled for use as component code.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct AccountComponentCode(Library);
10
11impl AccountComponentCode {
12    /// Returns a reference to the underlying [`Library`]
13    pub fn as_library(&self) -> &Library {
14        &self.0
15    }
16
17    /// Returns a reference to the code's [`MastForest`]
18    pub fn mast_forest(&self) -> &MastForest {
19        self.0.mast_forest().as_ref()
20    }
21
22    /// Consumes `self` and returns the underlying [`Library`]
23    pub fn into_library(self) -> Library {
24        self.0
25    }
26}
27
28impl AsRef<Library> for AccountComponentCode {
29    fn as_ref(&self) -> &Library {
30        self.as_library()
31    }
32}
33
34// CONVERSIONS
35// ================================================================================================
36
37impl From<Library> for AccountComponentCode {
38    fn from(value: Library) -> Self {
39        Self(value)
40    }
41}
42
43impl From<AccountComponentCode> for Library {
44    fn from(value: AccountComponentCode) -> Self {
45        value.into_library()
46    }
47}