1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
use std::fs; use std::io; use std::path::Path; use crate::transport::transport_factory::TransportFactory; #[derive(Clone)] pub struct FileInput; impl TransportFactory for FileInput { fn can_open(&self, path: &Path) -> bool { path.exists() } fn open(&self, path: &Path) -> io::Result<Box<dyn io::Read>> { match fs::File::open(path) { Ok(r) => Ok(Box::new(r)), Err(err) => return Err(io::Error::new(io::ErrorKind::Other, err)), } } fn box_clone(&self) -> Box<dyn TransportFactory> { Box::new((*self).clone()) } fn factory_name(&self) -> &str { "file" } }