intermodal/src/input.rs
2022-10-11 16:15:03 +02:00

30 lines
535 B
Rust

use crate::common::*;
pub struct Input {
source: InputTarget,
data: Vec<u8>,
}
impl Input {
pub fn new(source: InputTarget, data: Vec<u8>) -> Input {
Self { source, data }
}
pub fn data(&self) -> &[u8] {
&self.data
}
pub fn source(&self) -> &InputTarget {
&self.source
}
#[cfg(test)]
pub(crate) fn from_path(path: &Path) -> Result<Input> {
let data = fs::read(path).context(error::Filesystem { path })?;
Ok(Input {
source: InputTarget::Path(path.to_owned()),
data,
})
}
}