mirror of
				https://github.com/hannobraun/Fornjot
				synced 2025-11-03 21:57:22 +00:00 
			
		
		
		
	Add Insert trait
				
					
				
			This commit is contained in:
		
							parent
							
								
									9288a9bd36
								
							
						
					
					
						commit
						00618eb151
					
				
							
								
								
									
										53
									
								
								crates/fj-kernel/src/insert.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								crates/fj-kernel/src/insert.rs
									
									
									
									
									
										Normal file
									
								
							@ -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<Handle<Self>, <Self as Validate>::Error>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
macro_rules! impl_insert {
 | 
			
		||||
    ($($ty:ty, $store:ident;)*) => {
 | 
			
		||||
        $(
 | 
			
		||||
            impl Insert for $ty {
 | 
			
		||||
                fn insert(
 | 
			
		||||
                    self,
 | 
			
		||||
                    objects: &Objects,
 | 
			
		||||
                ) -> Result<Handle<Self>, <Self as Validate>::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;
 | 
			
		||||
);
 | 
			
		||||
@ -89,6 +89,7 @@
 | 
			
		||||
 | 
			
		||||
pub mod algorithms;
 | 
			
		||||
pub mod builder;
 | 
			
		||||
pub mod insert;
 | 
			
		||||
pub mod iter;
 | 
			
		||||
pub mod objects;
 | 
			
		||||
pub mod partial;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user