obographs_dev/io.rs
1use std::fs::File;
2use std::io::{BufRead, BufReader};
3use std::path::Path;
4
5use anyhow::{Context, Result};
6
7use crate::model::GraphDocument;
8
9impl GraphDocument {
10 /// Load Obographs graph document from provided path.
11 pub fn from_path<T>(path: T) -> Result<Self>
12 where
13 T: AsRef<Path>,
14 {
15 GraphDocument::from_reader(BufReader::new(File::open(path).context("Opening file")?))
16 }
17
18 /// Load Obographs graph document from a buffered reader.
19 pub fn from_reader<R>(read: R) -> Result<Self>
20 where
21 R: BufRead,
22 {
23 Ok(serde_json::from_reader(read).context("Reading JSON")?)
24 }
25}