1use std::path::Path;
2
3use write::IntoLibGroup;
4
5use crate::{error::{LibError, LibErrorContext}, model::LibLibrary};
6
7pub mod read;
8pub mod write;
9
10
11impl LibLibrary {
12 pub fn load_file<P: AsRef<Path>>(path: P) -> Result<Self, LibError> {
13 let path = path.as_ref();
14 let context = std::fs::read_to_string(path)
15 .map_err(LibError::Io)
16 .context(|| format!("read file{:?}", path))?;
17 let ast = read::parse_liberty(&context)
18 .context(|| "parse source to ast")?;
19 Self::from_ast(ast)
20 .context(|| "semantic ast to model")
21 }
22
23 pub fn save_file<P: AsRef<Path>>(self, path: P) -> Result<(), LibError> {
25 let group = self.into_group();
26 group.save_file(path)
27 }
28}