diff --git a/src/builder.rs b/src/builder.rs new file mode 100644 index 0000000..1f03be2 --- /dev/null +++ b/src/builder.rs @@ -0,0 +1,38 @@ +//! The builder module is focused on building a C3d struct for writing to a file. +//! It is focused on composing parts into a valid C3d struct. + +use crate::c3d::C3d; +use std::{error::Error, fmt}; + +/// The C3dBuilder is a struct that is used to build a C3d struct. +#[derive(Debug, Default)] +pub struct C3dBuilder { + pub(crate) c3d: C3d, +} + +impl C3dBuilder { + /// Creates a new C3dBuilder. + pub fn new() -> Self { + C3dBuilder { + c3d: C3d::default(), + } + } + + /// Consumes the builder and returns a C3d struct. + pub fn build(self) -> C3d { + self.c3d + } +} + +/// Reports errors in building a C3d struct. +#[derive(Debug)] +pub enum C3dBuilderError { + InvalidParameter, +} + +impl Error for C3dBuilderError {} +impl fmt::Display for C3dBuilderError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "C3dBuilderError: {:?}", self) + } +} diff --git a/src/lib.rs b/src/lib.rs index a809f99..4123a1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,26 +14,17 @@ use std::path::PathBuf; use std::{error::Error, fmt}; -#[path = "analog.rs"] pub mod analog; -#[path = "c3d.rs"] pub mod c3d; -#[path = "data.rs"] pub mod data; -#[path = "events.rs"] pub mod events; -#[path = "forces.rs"] pub mod forces; -#[path = "manufacturer.rs"] pub mod manufacturer; -#[path = "parameters.rs"] pub mod parameters; -#[path = "points.rs"] pub mod points; -#[path = "processor.rs"] mod processor; -#[path = "seg.rs"] pub mod seg; +pub mod builder; #[path = "file_formats/mod.rs"] pub mod file_formats; @@ -41,6 +32,7 @@ pub mod file_formats; pub use analog::Analog; pub use analog::AnalogFormat; pub use analog::AnalogOffset; +pub use builder::C3dBuilder; pub use c3d::C3d; pub use data::DataFormat; pub use data::MarkerPoint;