use std::{fs, io, path, pin}; pub fn open_file(path: &path::Path) -> io::Result> { match fs::File::open(path) { Ok(file) => Ok(Some(file)), Err(err) => match err.kind() { io::ErrorKind::NotFound => Ok(None), _ => Err(err), }, } } #[derive(thiserror::Error, Debug)] pub enum ParseFileError { #[error("io error: {0}")] IO(io::Error), #[error("parse error")] FromStr(ParseError), } pub fn parse_file( path: &path::Path, ) -> Result, ParseFileError> { match fs::read_to_string(path) { Ok(s) => Ok(Some(s.parse().map_err(ParseFileError::FromStr)?)), Err(err) => match err.kind() { io::ErrorKind::NotFound => Ok(None), _ => Err(ParseFileError::IO(err)), }, } } pub type BoxByteStream = futures::stream::BoxStream<'static, io::Result>; pub type BoxFuture<'a, O> = pin::Pin + Send + 'a>>;