From 1cd918d6b1100c7c9f3f49b9d487a3cd6e692841 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Mar 2023 13:56:27 +0100 Subject: [PATCH 1/9] Remove unused code --- crates/fj-kernel/src/objects/object.rs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/crates/fj-kernel/src/objects/object.rs b/crates/fj-kernel/src/objects/object.rs index 603453ba4..2c22aa16f 100644 --- a/crates/fj-kernel/src/objects/object.rs +++ b/crates/fj-kernel/src/objects/object.rs @@ -1,5 +1,3 @@ -use std::any::Any; - use crate::{ objects::{ Cycle, Face, GlobalEdge, HalfEdge, Objects, Shell, Sketch, Solid, @@ -24,23 +22,6 @@ macro_rules! object { )* } - impl Object { - /// Convert the `Object` into the requested inner type - pub fn as_inner(&self) -> Option<&F::Form> - where - Self: 'static, - F::Form: Any, - { - match self { - $( - Self::$ty(object) => - (object as &dyn Any).downcast_ref(), - - )* - } - } - } - impl Object { /// Access the ID of the object pub fn id(&self) -> ObjectId { From 2460b07c0c2e4a5797c3b82adca876336cfd7e6f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 21 Mar 2023 12:26:57 +0100 Subject: [PATCH 2/9] Add missing re-exports --- crates/fj-kernel/src/services/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/services/mod.rs b/crates/fj-kernel/src/services/mod.rs index a42373e82..5128eaccc 100644 --- a/crates/fj-kernel/src/services/mod.rs +++ b/crates/fj-kernel/src/services/mod.rs @@ -13,7 +13,7 @@ use parking_lot::Mutex; use crate::objects::Objects; pub use self::{ - objects::ServiceObjectsExt, + objects::{InsertObject, ObjectToInsert, ServiceObjectsExt}, service::{Service, State}, validation::{Validation, ValidationFailed}, }; From 0505d514f70945a755c6a8d4855bf7359bf3f932 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 21 Mar 2023 12:27:48 +0100 Subject: [PATCH 3/9] Update name of command --- crates/fj-kernel/src/services/mod.rs | 2 +- crates/fj-kernel/src/services/objects.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/services/mod.rs b/crates/fj-kernel/src/services/mod.rs index 5128eaccc..b060228d7 100644 --- a/crates/fj-kernel/src/services/mod.rs +++ b/crates/fj-kernel/src/services/mod.rs @@ -13,7 +13,7 @@ use parking_lot::Mutex; use crate::objects::Objects; pub use self::{ - objects::{InsertObject, ObjectToInsert, ServiceObjectsExt}, + objects::{ObjectToInsert, Operation, ServiceObjectsExt}, service::{Service, State}, validation::{Validation, ValidationFailed}, }; diff --git a/crates/fj-kernel/src/services/objects.rs b/crates/fj-kernel/src/services/objects.rs index a5defbe26..4ff7d61e1 100644 --- a/crates/fj-kernel/src/services/objects.rs +++ b/crates/fj-kernel/src/services/objects.rs @@ -6,7 +6,7 @@ use crate::{ use super::{Service, State}; impl State for Objects { - type Command = InsertObject; + type Command = Operation; type Event = ObjectToInsert; fn decide(&self, command: Self::Command, events: &mut Vec) { @@ -26,7 +26,7 @@ impl State for Objects { /// You might prefer to use [`ServiceObjectsExt::insert`], which is a convenient /// wrapper around `Service::execute`. #[derive(Clone, Debug)] -pub struct InsertObject { +pub struct Operation { /// The object to insert pub object: Object, } @@ -51,7 +51,7 @@ impl ServiceObjectsExt for Service { where (Handle, T): Into>, { - self.execute(InsertObject { + self.execute(Operation { object: (handle, object).into(), }); } From 9c5061e2ad06f7e3e83131774416ab329aa8d18a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 21 Mar 2023 12:32:32 +0100 Subject: [PATCH 4/9] Simplify name of event --- crates/fj-kernel/src/services/mod.rs | 2 +- crates/fj-kernel/src/services/objects.rs | 6 +++--- crates/fj-kernel/src/services/validation.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/services/mod.rs b/crates/fj-kernel/src/services/mod.rs index b060228d7..346a3ef7a 100644 --- a/crates/fj-kernel/src/services/mod.rs +++ b/crates/fj-kernel/src/services/mod.rs @@ -13,7 +13,7 @@ use parking_lot::Mutex; use crate::objects::Objects; pub use self::{ - objects::{ObjectToInsert, Operation, ServiceObjectsExt}, + objects::{InsertObject, Operation, ServiceObjectsExt}, service::{Service, State}, validation::{Validation, ValidationFailed}, }; diff --git a/crates/fj-kernel/src/services/objects.rs b/crates/fj-kernel/src/services/objects.rs index 4ff7d61e1..0fb38b70c 100644 --- a/crates/fj-kernel/src/services/objects.rs +++ b/crates/fj-kernel/src/services/objects.rs @@ -7,10 +7,10 @@ use super::{Service, State}; impl State for Objects { type Command = Operation; - type Event = ObjectToInsert; + type Event = InsertObject; fn decide(&self, command: Self::Command, events: &mut Vec) { - let event = ObjectToInsert { + let event = InsertObject { object: command.object, }; events.push(event); @@ -33,7 +33,7 @@ pub struct Operation { /// Event produced by `Service` #[derive(Clone, Debug)] -pub struct ObjectToInsert { +pub struct InsertObject { /// The object to insert pub object: Object, } diff --git a/crates/fj-kernel/src/services/validation.rs b/crates/fj-kernel/src/services/validation.rs index bd7369201..5e0717a8f 100644 --- a/crates/fj-kernel/src/services/validation.rs +++ b/crates/fj-kernel/src/services/validation.rs @@ -6,7 +6,7 @@ use crate::{ validate::ValidationError, }; -use super::{objects::ObjectToInsert, State}; +use super::{objects::InsertObject, State}; /// Errors that occurred while validating the objects inserted into the stores #[derive(Default)] @@ -33,7 +33,7 @@ impl Drop for Validation { } impl State for Validation { - type Command = ObjectToInsert; + type Command = InsertObject; type Event = ValidationFailed; fn decide(&self, command: Self::Command, events: &mut Vec) { From 6d6f32de9da09b9b338e8882cbe17b69af1ee264 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 21 Mar 2023 12:29:22 +0100 Subject: [PATCH 5/9] Refactor code to prepare for follow-on change --- crates/fj-kernel/src/services/objects.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/services/objects.rs b/crates/fj-kernel/src/services/objects.rs index 0fb38b70c..97737dc1d 100644 --- a/crates/fj-kernel/src/services/objects.rs +++ b/crates/fj-kernel/src/services/objects.rs @@ -10,9 +10,8 @@ impl State for Objects { type Event = InsertObject; fn decide(&self, command: Self::Command, events: &mut Vec) { - let event = InsertObject { - object: command.object, - }; + let object = command.object; + let event = InsertObject { object }; events.push(event); } From c3c5f9ee28ff5fd8574a4c5fbf759b4a83c1ab8d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 21 Mar 2023 12:31:38 +0100 Subject: [PATCH 6/9] Convert `Operation` into an enum --- crates/fj-kernel/src/services/objects.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/services/objects.rs b/crates/fj-kernel/src/services/objects.rs index 97737dc1d..d1b4af794 100644 --- a/crates/fj-kernel/src/services/objects.rs +++ b/crates/fj-kernel/src/services/objects.rs @@ -10,7 +10,7 @@ impl State for Objects { type Event = InsertObject; fn decide(&self, command: Self::Command, events: &mut Vec) { - let object = command.object; + let Operation::InsertObject { object } = command; let event = InsertObject { object }; events.push(event); } @@ -21,13 +21,19 @@ impl State for Objects { } /// Command for `Service` -/// -/// You might prefer to use [`ServiceObjectsExt::insert`], which is a convenient -/// wrapper around `Service::execute`. #[derive(Clone, Debug)] -pub struct Operation { - /// The object to insert - pub object: Object, +pub enum Operation { + /// Insert an object into the stores + /// + /// This is the one primitive operation that all other operations are built + /// upon. + /// + /// You might prefer to use [`ServiceObjectsExt::insert`], which is a + /// convenient wrapper around `Service::execute`. + InsertObject { + /// The object to insert + object: Object, + }, } /// Event produced by `Service` @@ -50,7 +56,7 @@ impl ServiceObjectsExt for Service { where (Handle, T): Into>, { - self.execute(Operation { + self.execute(Operation::InsertObject { object: (handle, object).into(), }); } From 2b36ea2487b85a894ca19756b8c5ff7901ef7836 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 21 Mar 2023 12:36:37 +0100 Subject: [PATCH 7/9] Remove unused trait implementation It's getting in the way of adding complex operations, which I'm planning to add in the form of a boxed trait. The boxed trait can't be object-safe, if it needs to be `Clone`. --- crates/fj-kernel/src/services/objects.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/services/objects.rs b/crates/fj-kernel/src/services/objects.rs index d1b4af794..bd8c6d026 100644 --- a/crates/fj-kernel/src/services/objects.rs +++ b/crates/fj-kernel/src/services/objects.rs @@ -21,7 +21,7 @@ impl State for Objects { } /// Command for `Service` -#[derive(Clone, Debug)] +#[derive(Debug)] pub enum Operation { /// Insert an object into the stores /// From cb578fc9028a43e3002b45bd077513763e82c038 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 21 Mar 2023 12:38:48 +0100 Subject: [PATCH 8/9] Inline redundant variable --- crates/fj-kernel/src/services/objects.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/services/objects.rs b/crates/fj-kernel/src/services/objects.rs index bd8c6d026..fb919d04f 100644 --- a/crates/fj-kernel/src/services/objects.rs +++ b/crates/fj-kernel/src/services/objects.rs @@ -11,8 +11,7 @@ impl State for Objects { fn decide(&self, command: Self::Command, events: &mut Vec) { let Operation::InsertObject { object } = command; - let event = InsertObject { object }; - events.push(event); + events.push(InsertObject { object }); } fn evolve(&mut self, event: &Self::Event) { From 310a48ee4e734272e469a2964a8dd106dbf423c1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 22 Mar 2023 13:54:20 +0100 Subject: [PATCH 9/9] Simplify `ServiceObjectsExt::insert` --- crates/fj-kernel/src/insert.rs | 2 +- crates/fj-kernel/src/services/objects.rs | 18 ++++-------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/crates/fj-kernel/src/insert.rs b/crates/fj-kernel/src/insert.rs index 50e9bb063..90b50ff41 100644 --- a/crates/fj-kernel/src/insert.rs +++ b/crates/fj-kernel/src/insert.rs @@ -25,7 +25,7 @@ macro_rules! impl_insert { fn insert(self, objects: &mut Service) -> Handle { let handle = objects.$store.reserve(); - objects.insert(handle.clone(), self); + objects.insert((handle.clone(), self).into()); handle } } diff --git a/crates/fj-kernel/src/services/objects.rs b/crates/fj-kernel/src/services/objects.rs index fb919d04f..d5f530fa8 100644 --- a/crates/fj-kernel/src/services/objects.rs +++ b/crates/fj-kernel/src/services/objects.rs @@ -1,7 +1,4 @@ -use crate::{ - objects::{Object, Objects, WithHandle}, - storage::Handle, -}; +use crate::objects::{Object, Objects, WithHandle}; use super::{Service, State}; @@ -45,18 +42,11 @@ pub struct InsertObject { /// Convenient API for `Service` pub trait ServiceObjectsExt { /// Insert an object - fn insert(&mut self, handle: Handle, object: T) - where - (Handle, T): Into>; + fn insert(&mut self, object: Object); } impl ServiceObjectsExt for Service { - fn insert(&mut self, handle: Handle, object: T) - where - (Handle, T): Into>, - { - self.execute(Operation::InsertObject { - object: (handle, object).into(), - }); + fn insert(&mut self, object: Object) { + self.execute(Operation::InsertObject { object }); } }