summaryrefslogtreecommitdiffstats
path: root/library/backtrace/src/symbolize/gimli/mmap_fake.rs
blob: ce50964154dc20f42a4778537c5723bdeab208d0 (plain)
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
use super::{mystd::io::Read, File};
use alloc::vec::Vec;
use core::ops::Deref;

pub struct Mmap {
    vec: Vec<u8>,
}

impl Mmap {
    pub unsafe fn map(mut file: &File, len: usize) -> Option<Mmap> {
        let mut mmap = Mmap {
            vec: Vec::with_capacity(len),
        };
        file.read_to_end(&mut mmap.vec).ok()?;
        Some(mmap)
    }
}

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

    fn deref(&self) -> &[u8] {
        &self.vec[..]
    }
}