Skip to main content

fso_graph_builder/input/
binary.rs

1use std::{
2    convert::TryFrom,
3    marker::PhantomData,
4    path::{Path, PathBuf},
5};
6
7use byte_slice_cast::ToByteSlice;
8
9use crate::{index::Idx, Error};
10
11use super::{InputCapabilities, InputPath};
12
13/// Reads a graph that has been written via
14/// [`crate::graph_ops::SerializeGraphOp`].
15pub struct BinaryInput<NI: Idx + ToByteSlice> {
16    _idx: PhantomData<NI>,
17}
18
19impl<NI: Idx + ToByteSlice> Default for BinaryInput<NI> {
20    fn default() -> Self {
21        Self { _idx: PhantomData }
22    }
23}
24
25impl<NI: Idx + ToByteSlice> InputCapabilities<NI> for BinaryInput<NI> {
26    type GraphInput = PathBuf;
27}
28
29impl<P> TryFrom<InputPath<P>> for PathBuf
30where
31    P: AsRef<Path>,
32{
33    type Error = Error;
34
35    fn try_from(path: InputPath<P>) -> Result<Self, Self::Error> {
36        Ok(PathBuf::from(path.0.as_ref()))
37    }
38}