//! Module containing all the logic for exporting 3D models. pub mod obj; use std::io; use std::io::Write; use std::fmt; use parser::Element; use model::Model; /// An error occured during export. pub enum ExportError { /// An IO error occured when creating files or directories. IoError(io::Error), } impl fmt::Display for ExportError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { ExportError::IoError(ref e) => write!(f, "IoError occured: {}", e), } } } impl From for ExportError { fn from(e: io::Error) -> Self { ExportError::IoError(e) } } /// Exports a 3D model to a certain format. pub trait Exporter { /// The type of errors the exporter will return in case of errors. /// /// The errors can be of many things, we can't know everything in this create, so this type /// will enable you to use custom errors. type Error; /// Performs the export in the specified output directory. fn export(&self, model: &Model, output_dir: &str) -> Result<(), Self::Error>; } /// Serialize a 3D element. pub trait ElementSerializer { /// Performs the serialization. /// /// Writes the serialization on the output and returns Err if an error occured. fn serialize(&self, element: Element, output: &mut W) -> Result; }