stak_module/
static.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Static modules.

use crate::{Guard, Module};
use core::ops::Deref;

/// A static module.
#[derive(Debug)]
pub struct StaticModule {
    bytecode: &'static [u8],
}

impl StaticModule {
    /// Creates a static module.
    pub const fn new(bytecode: &'static [u8]) -> Self {
        Self { bytecode }
    }
}

impl<'a> Module<'a> for StaticModule {
    type Guard = StaticGuard;

    fn bytecode(&'a self) -> Self::Guard {
        StaticGuard(self.bytecode)
    }
}

/// A read guard against a static module.
pub struct StaticGuard(&'static [u8]);

impl Deref for StaticGuard {
    type Target = [u8];

    fn deref(&self) -> &Self::Target {
        self.0
    }
}

impl Guard for StaticGuard {}