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/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 { diff --git a/crates/fj-kernel/src/services/mod.rs b/crates/fj-kernel/src/services/mod.rs index a42373e82..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::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 a5defbe26..d5f530fa8 100644 --- a/crates/fj-kernel/src/services/objects.rs +++ b/crates/fj-kernel/src/services/objects.rs @@ -1,19 +1,14 @@ -use crate::{ - objects::{Object, Objects, WithHandle}, - storage::Handle, -}; +use crate::objects::{Object, Objects, WithHandle}; use super::{Service, State}; impl State for Objects { - type Command = InsertObject; - type Event = ObjectToInsert; + type Command = Operation; + type Event = InsertObject; fn decide(&self, command: Self::Command, events: &mut Vec) { - let event = ObjectToInsert { - object: command.object, - }; - events.push(event); + let Operation::InsertObject { object } = command; + events.push(InsertObject { object }); } fn evolve(&mut self, event: &Self::Event) { @@ -22,18 +17,24 @@ 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 InsertObject { - /// The object to insert - pub object: Object, +#[derive(Debug)] +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` #[derive(Clone, Debug)] -pub struct ObjectToInsert { +pub struct InsertObject { /// The object to insert pub object: Object, } @@ -41,18 +42,11 @@ pub struct ObjectToInsert { /// 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(InsertObject { - object: (handle, object).into(), - }); + fn insert(&mut self, object: Object) { + self.execute(Operation::InsertObject { 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) {