use std::path::Path;
use crate::graph::CodeGraph;
use crate::types::{AcbError, AcbResult};
use super::reader::AcbReader;
pub struct MappedCodeGraph {
_mmap: memmap2::Mmap,
graph: CodeGraph,
}
impl MappedCodeGraph {
pub fn open(path: &Path) -> AcbResult<Self> {
if !path.exists() {
return Err(AcbError::PathNotFound(path.to_path_buf()));
}
let file = std::fs::File::open(path)?;
let mmap = unsafe { memmap2::Mmap::map(&file)? };
let graph = AcbReader::read_from_data(&mmap)?;
Ok(Self { _mmap: mmap, graph })
}
pub fn graph(&self) -> &CodeGraph {
&self.graph
}
pub fn into_graph(self) -> CodeGraph {
self.graph
}
}