miden_standards/
standards_lib.rs1use alloc::sync::Arc;
2
3use miden_protocol::assembly::Library;
4use miden_protocol::assembly::mast::MastForest;
5use miden_protocol::utils::serde::Deserializable;
6use miden_protocol::utils::sync::LazyLock;
7
8const STANDARDS_LIB_BYTES: &[u8] =
12 include_bytes!(concat!(env!("OUT_DIR"), "/assets/standards.masl"));
13
14#[derive(Clone)]
18pub struct StandardsLib(Library);
19
20impl StandardsLib {
21 pub fn mast_forest(&self) -> &Arc<MastForest> {
23 self.0.mast_forest()
24 }
25}
26
27impl AsRef<Library> for StandardsLib {
28 fn as_ref(&self) -> &Library {
29 &self.0
30 }
31}
32
33impl From<StandardsLib> for Library {
34 fn from(value: StandardsLib) -> Self {
35 value.0
36 }
37}
38
39impl Default for StandardsLib {
40 fn default() -> Self {
41 static STANDARDS_LIB: LazyLock<StandardsLib> = LazyLock::new(|| {
42 let contents = Library::read_from_bytes(STANDARDS_LIB_BYTES)
43 .expect("standards lib masl should be well-formed");
44 StandardsLib(contents)
45 });
46 STANDARDS_LIB.clone()
47 }
48}
49
50#[cfg(all(test, feature = "std"))]
55mod tests {
56 use miden_protocol::assembly::Path;
57
58 use super::StandardsLib;
59
60 #[test]
61 fn test_compile() {
62 let path = Path::new("::miden::standards::faucets::basic_fungible::distribute");
63 let miden = StandardsLib::default();
64 let exists = miden.0.module_infos().any(|module| {
65 module
66 .procedures()
67 .any(|(_, proc)| module.path().join(&proc.name).as_path() == path)
68 });
69
70 assert!(exists);
71 }
72}