vmi_core/
page.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
use std::{ops::Deref, rc::Rc};

/// A page of memory that has been mapped from the guest virtual machine.
#[derive(Clone)]
pub struct VmiMappedPage(Rc<Box<dyn Deref<Target = [u8]>>>);

impl VmiMappedPage {
    /// Creates a new mapped page.
    pub fn new<T>(inner: T) -> Self
    where
        T: Deref<Target = [u8]> + 'static,
    {
        Self(Rc::new(Box::new(inner)))
    }
}

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

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

impl AsRef<[u8]> for VmiMappedPage {
    fn as_ref(&self) -> &[u8] {
        self.deref()
    }
}