#![forbid(unsafe_code)]
mod error;
mod plot;
mod read;
mod types;
mod write;
pub use error::Error;
pub use plot::{Data, Plot, Variable};
pub use types::VarType;
pub use write::{Format, fmt_e};
#[derive(Clone, Debug, PartialEq)]
pub struct Rawfile {
pub plots: Vec<Plot>,
pub warnings: Vec<String>,
}
impl Rawfile {
pub fn parse(bytes: &[u8]) -> Result<Self, Error> {
read::parse(bytes)
}
pub fn read_from(path: impl AsRef<std::path::Path>) -> Result<Self, Error> {
Self::parse(&std::fs::read(path)?)
}
pub fn write(&self, w: &mut impl std::io::Write, format: Format) -> std::io::Result<()> {
for plot in &self.plots {
plot.write(w, format)?;
}
Ok(())
}
pub fn to_bytes(&self, format: Format) -> Vec<u8> {
let mut buf = Vec::new();
self.write(&mut buf, format)
.expect("writing to a Vec cannot fail");
buf
}
}