diff --git a/crates/fj-kernel/src/insert.rs b/crates/fj-kernel/src/insert.rs new file mode 100644 index 000000000..44aaed099 --- /dev/null +++ b/crates/fj-kernel/src/insert.rs @@ -0,0 +1,53 @@ +//! Convenience trait to insert objects into their respective stores +//! +//! See [`Insert`]. + +use crate::{ + objects::{ + Curve, Cycle, Face, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, + Objects, Shell, Sketch, Solid, Surface, SurfaceVertex, Vertex, + }, + storage::Handle, + validate::Validate, +}; + +/// Convenience trait to insert objects into their respective stores +pub trait Insert: Sized + Validate { + // TASK: Make error more specific. + /// Insert the object into its respective store + fn insert( + self, + objects: &Objects, + ) -> Result, ::Error>; +} + +macro_rules! impl_insert { + ($($ty:ty, $store:ident;)*) => { + $( + impl Insert for $ty { + fn insert( + self, + objects: &Objects, + ) -> Result, ::Error> { + objects.$store.insert(self) + } + } + )* + }; +} + +impl_insert!( + Curve, curves; + Cycle, cycles; + Face, faces; + GlobalCurve, global_curves; + GlobalEdge, global_edges; + GlobalVertex, global_vertices; + HalfEdge, half_edges; + Shell, shells; + Sketch, sketches; + Solid, solids; + SurfaceVertex, surface_vertices; + Surface, surfaces; + Vertex, vertices; +); diff --git a/crates/fj-kernel/src/lib.rs b/crates/fj-kernel/src/lib.rs index 08e560e19..607c7b11c 100644 --- a/crates/fj-kernel/src/lib.rs +++ b/crates/fj-kernel/src/lib.rs @@ -89,6 +89,7 @@ pub mod algorithms; pub mod builder; +pub mod insert; pub mod iter; pub mod objects; pub mod partial;