use super::InterchangeError;
use super::model::Model;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FormatCapability {
pub read: bool,
pub write: bool,
pub streaming: bool,
pub lossless: bool,
}
impl FormatCapability {
pub const FULL: Self = Self {
read: true,
write: true,
streaming: false,
lossless: true,
};
pub const READ_ONLY: Self = Self {
read: true,
write: false,
streaming: false,
lossless: true,
};
pub const WRITE_ONLY: Self = Self {
read: false,
write: true,
streaming: false,
lossless: true,
};
}
pub trait ModelFormat: Send + Sync {
fn name(&self) -> &'static str;
fn extensions(&self) -> &'static [&'static str];
fn mime_type(&self) -> &'static str;
fn capabilities(&self) -> FormatCapability;
fn read(&self, input: &[u8]) -> Result<Model, InterchangeError>;
fn write(&self, model: &Model) -> Result<Vec<u8>, InterchangeError>;
fn validate(&self, input: &[u8]) -> Result<(), InterchangeError> {
let _ = input;
Ok(())
}
}