diff --git a/crates/fj-core/src/operations/insert.rs b/crates/fj-core/src/operations/insert/insert_trait.rs similarity index 76% rename from crates/fj-core/src/operations/insert.rs rename to crates/fj-core/src/operations/insert/insert_trait.rs index 2e6f382dc..cd19325c2 100644 --- a/crates/fj-core/src/operations/insert.rs +++ b/crates/fj-core/src/operations/insert/insert_trait.rs @@ -3,11 +3,12 @@ use crate::{ Curve, Cycle, Face, GlobalEdge, HalfEdge, Region, Shell, Sketch, Solid, Surface, Vertex, }, + operations::{Polygon, TetrahedronShell}, services::Services, storage::Handle, }; -use super::{Polygon, TetrahedronShell}; +use super::{IsInsertedNo, IsInsertedYes}; /// Insert an object into its respective store /// @@ -56,33 +57,6 @@ impl_insert!( Vertex, vertices; ); -/// Indicate whether an object has been inserted -/// -/// Intended to be used as a type parameter bound for structs that need to track -/// whether their contents have been inserted or not. -pub trait IsInserted { - /// The type of the object for which the insertion status is tracked - type T; -} - -/// Indicate that an object has been inserted -/// -/// See [`IsInserted`]. -pub struct IsInsertedYes; - -impl IsInserted for IsInsertedYes { - type T = Handle; -} - -/// Indicate that an object has not been inserted -/// -/// See [`IsInserted`]. -pub struct IsInsertedNo; - -impl IsInserted for IsInsertedNo { - type T = T; -} - impl Insert for Polygon { type Inserted = Polygon; diff --git a/crates/fj-core/src/operations/insert/is_inserted.rs b/crates/fj-core/src/operations/insert/is_inserted.rs new file mode 100644 index 000000000..992e2f43d --- /dev/null +++ b/crates/fj-core/src/operations/insert/is_inserted.rs @@ -0,0 +1,30 @@ +use std::borrow::Borrow; + +use crate::storage::Handle; + +/// Indicate whether an object has been inserted +/// +/// Intended to be used as a type parameter bound for structs that need to track +/// whether their contents have been inserted or not. +pub trait IsInserted { + /// The type of the object for which the insertion status is tracked + type T: Borrow; +} + +/// Indicate that an object has been inserted +/// +/// See [`IsInserted`]. +pub struct IsInsertedYes; + +impl IsInserted for IsInsertedYes { + type T = Handle; +} + +/// Indicate that an object has not been inserted +/// +/// See [`IsInserted`]. +pub struct IsInsertedNo; + +impl IsInserted for IsInsertedNo { + type T = T; +} diff --git a/crates/fj-core/src/operations/insert/mod.rs b/crates/fj-core/src/operations/insert/mod.rs new file mode 100644 index 000000000..bc3815384 --- /dev/null +++ b/crates/fj-core/src/operations/insert/mod.rs @@ -0,0 +1,7 @@ +mod insert_trait; +mod is_inserted; + +pub use self::{ + insert_trait::Insert, + is_inserted::{IsInserted, IsInsertedNo, IsInsertedYes}, +}; diff --git a/crates/fj-core/src/storage/handle.rs b/crates/fj-core/src/storage/handle.rs index 15b5f8d18..63eea2908 100644 --- a/crates/fj-core/src/storage/handle.rs +++ b/crates/fj-core/src/storage/handle.rs @@ -1,4 +1,6 @@ -use std::{any::type_name, cmp::Ordering, fmt, hash::Hash, ops::Deref}; +use std::{ + any::type_name, borrow::Borrow, cmp::Ordering, fmt, hash::Hash, ops::Deref, +}; use super::{blocks::Index, store::StoreInner}; @@ -82,6 +84,12 @@ impl Deref for Handle { } } +impl Borrow for Handle { + fn borrow(&self) -> &T { + self.deref() + } +} + impl Clone for Handle { fn clone(&self) -> Self { Self {