pub trait Codec {
// Required methods
fn name(&self) -> &'static str;
fn extensions(&self) -> &'static [&'static str];
fn read_bytes(&self, bytes: &[u8]) -> Result<Model, ModelError>;
fn write(
&self,
model: &Model,
out: &mut dyn Write,
) -> Result<(), ModelError>;
// Provided methods
fn detect(&self, _bytes: &[u8]) -> bool { ... }
fn read_owned(&self, bytes: Vec<u8>) -> Result<Model, ModelError> { ... }
fn read_from(&self, reader: &mut dyn Read) -> Result<Model, ModelError> { ... }
fn read_path(&self, path: &Path) -> Result<Model, ModelError> { ... }
fn write_path(&self, model: &Model, path: &Path) -> Result<(), ModelError> { ... }
fn write_bytes(&self, model: &Model) -> Result<Vec<u8>, ModelError> { ... }
}Expand description
Read and write one concrete IFC serialization.
Implementors are stateless; they carry configuration only.
Required Methods§
Sourcefn extensions(&self) -> &'static [&'static str]
fn extensions(&self) -> &'static [&'static str]
Conventional file extensions, lower-case, without the dot.
Sourcefn read_bytes(&self, bytes: &[u8]) -> Result<Model, ModelError>
fn read_bytes(&self, bytes: &[u8]) -> Result<Model, ModelError>
Parse a model from bytes.
Bytes rather than &str because IFC files are not guaranteed UTF-8:
STEP escapes non-ASCII text, and a stray raw byte must not abort the
parse of an otherwise valid file.
Provided Methods§
Sourcefn detect(&self, _bytes: &[u8]) -> bool
fn detect(&self, _bytes: &[u8]) -> bool
Does this look like a file this codec can read?
Content sniffing, so a file with the wrong extension still opens.
Defaults to false — a codec that cannot cheaply recognize its own
format should say so rather than claim every input, which would make
codec selection order-dependent.
Sourcefn read_owned(&self, bytes: Vec<u8>) -> Result<Model, ModelError>
fn read_owned(&self, bytes: Vec<u8>) -> Result<Model, ModelError>
Parse a model from a buffer the model may keep.
A codec that loads lazily keeps its source for the model’s lifetime;
handing it the buffer avoids copying the whole input once more.
Defaults to Codec::read_bytes.
Sourcefn read_from(&self, reader: &mut dyn Read) -> Result<Model, ModelError>
fn read_from(&self, reader: &mut dyn Read) -> Result<Model, ModelError>
Parse from any reader. Override when the format can stream.
Sourcefn read_path(&self, path: &Path) -> Result<Model, ModelError>
fn read_path(&self, path: &Path) -> Result<Model, ModelError>
Parse a file from disk.
Override this when the codec can memory-map instead of reading into a
heap buffer; ifc-step does exactly that for large models.
Sourcefn write_path(&self, model: &Model, path: &Path) -> Result<(), ModelError>
fn write_path(&self, model: &Model, path: &Path) -> Result<(), ModelError>
Serialize to a file on disk.
Sourcefn write_bytes(&self, model: &Model) -> Result<Vec<u8>, ModelError>
fn write_bytes(&self, model: &Model) -> Result<Vec<u8>, ModelError>
Serialize to a byte vector.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".