stak_module/
static.rs

1//! Static modules.
2
3use crate::{Guard, Module};
4use core::ops::Deref;
5
6/// A static module.
7#[derive(Debug)]
8pub struct StaticModule {
9    bytecode: &'static [u8],
10}
11
12impl StaticModule {
13    /// Creates a static module.
14    pub const fn new(bytecode: &'static [u8]) -> Self {
15        Self { bytecode }
16    }
17}
18
19impl<'a> Module<'a> for StaticModule {
20    type Guard = StaticGuard;
21
22    fn bytecode(&'a self) -> Self::Guard {
23        StaticGuard(self.bytecode)
24    }
25}
26
27/// A read guard against a static module.
28pub struct StaticGuard(&'static [u8]);
29
30impl Deref for StaticGuard {
31    type Target = [u8];
32
33    fn deref(&self) -> &Self::Target {
34        self.0
35    }
36}
37
38impl Guard for StaticGuard {}