From 7265180f87891a3cb39168791cdba04ed3dd3fa3 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:25:04 +0100 Subject: [PATCH 01/27] Add `Event` trait --- crates/fj-core/src/layers/layer.rs | 3 +++ crates/fj-core/src/layers/mod.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index efa1efcbe..32a106fc3 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -95,3 +95,6 @@ pub trait State { /// [`State::decide`], and encoded into the event. fn evolve(&mut self, event: &Self::Event); } + +/// An event that encodes a change to a layer's state +pub trait Event {} diff --git a/crates/fj-core/src/layers/mod.rs b/crates/fj-core/src/layers/mod.rs index 953ff94f3..4c78af2ed 100644 --- a/crates/fj-core/src/layers/mod.rs +++ b/crates/fj-core/src/layers/mod.rs @@ -9,6 +9,6 @@ mod layer; mod layers; pub use self::{ - layer::{Layer, State}, + layer::{Event, Layer, State}, layers::Layers, }; From 9a9877df8f13f672ba279f010b64f4d6325a4cdc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:25:19 +0100 Subject: [PATCH 02/27] Require `State` to be `Sized` --- crates/fj-core/src/layers/layer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index 32a106fc3..37fb6ef27 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -67,7 +67,7 @@ where /// the consumer of this trait's API. /// /// See [`Layer`] for a more detailed explanation. -pub trait State { +pub trait State: Sized { /// A command that encodes a request to update the state /// /// Commands are processed by [`State::decide`]. From ce95d0b3615ebd931acc6f99cbc4affb7f769452 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:25:40 +0100 Subject: [PATCH 03/27] Require `State::Event` to implement `Event` --- crates/fj-core/src/layers/layer.rs | 2 +- crates/fj-core/src/layers/objects.rs | 4 +++- crates/fj-core/src/layers/validation.rs | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index 37fb6ef27..9ef337889 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -77,7 +77,7 @@ pub trait State: Sized { /// /// Events are produced by [`State::decide`] and processed by /// [`State::evolve`]. - type Event; + type Event: Event; /// Decide how to react to the provided command /// diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index 4d6828ab4..a1f025928 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -5,7 +5,7 @@ use crate::{ validate::Validation, }; -use super::{Layer, State}; +use super::{Event, Layer, State}; impl Layer { /// Insert and object into the stores @@ -60,3 +60,5 @@ pub enum ObjectsEvent { object: AnyObject, }, } + +impl Event for ObjectsEvent {} diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index b826045e4..3e5836a0c 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -5,7 +5,7 @@ use crate::{ validate::{Validation, ValidationError, ValidationErrors}, }; -use super::{objects::ObjectsEvent, Layer, State}; +use super::{objects::ObjectsEvent, Event, Layer, State}; impl Layer { /// Handler for [`ObjectsEvent`] @@ -80,3 +80,5 @@ pub enum ValidationEvent { err: ValidationError, }, } + +impl Event for ValidationEvent {} From 692b325bb2b260365f8b08bc5685bf512b73228d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:36:02 +0100 Subject: [PATCH 04/27] Convert `State::evolve` into `Event::evolve` --- crates/fj-core/src/layers/layer.rs | 14 +++++++------- crates/fj-core/src/layers/objects.rs | 12 ++++++------ crates/fj-core/src/layers/validation.rs | 18 +++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index 9ef337889..6485fef12 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -34,7 +34,7 @@ impl Layer { self.state.decide(command, events); for event in events { - self.state.evolve(event); + event.evolve(&mut self.state); } } @@ -76,7 +76,7 @@ pub trait State: Sized { /// An event that encodes a change to the state /// /// Events are produced by [`State::decide`] and processed by - /// [`State::evolve`]. + /// [`Event::evolve`]. type Event: Event; /// Decide how to react to the provided command @@ -84,8 +84,11 @@ pub trait State: Sized { /// If the command must result in changes to the state, any number of events /// that describe these state changes can be produced. fn decide(&self, command: Self::Command, events: &mut Vec); +} - /// Evolve the state according to the provided event +/// An event that encodes a change to a layer's state +pub trait Event { + /// Evolve the provided state /// /// This is the only method that gets mutable access to the state, making /// sure that all changes to the state are captured as events. @@ -93,8 +96,5 @@ pub trait State: Sized { /// Implementations of this method are supposed to be relatively dumb. Any /// decisions that go into updating the state should be made in /// [`State::decide`], and encoded into the event. - fn evolve(&mut self, event: &Self::Event); + fn evolve(&self, state: &mut S); } - -/// An event that encodes a change to a layer's state -pub trait Event {} diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index a1f025928..f3677c933 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -31,11 +31,6 @@ impl State for Objects { let ObjectsCommand::InsertObject { object } = command; events.push(ObjectsEvent::InsertObject { object }); } - - fn evolve(&mut self, event: &Self::Event) { - let ObjectsEvent::InsertObject { object } = event; - object.clone().insert(self); - } } /// Command for `Layer` @@ -61,4 +56,9 @@ pub enum ObjectsEvent { }, } -impl Event for ObjectsEvent {} +impl Event for ObjectsEvent { + fn evolve(&self, state: &mut Objects) { + let ObjectsEvent::InsertObject { object } = self; + object.clone().insert(state); + } +} diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 3e5836a0c..e26d4d0a1 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -49,14 +49,6 @@ impl State for Validation { } } } - - fn evolve(&mut self, event: &Self::Event) { - match event { - ValidationEvent::ValidationFailed { object, err } => { - self.errors.insert(object.id(), err.clone()); - } - } - } } /// Command for `Layer` @@ -81,4 +73,12 @@ pub enum ValidationEvent { }, } -impl Event for ValidationEvent {} +impl Event for ValidationEvent { + fn evolve(&self, state: &mut Validation) { + match self { + ValidationEvent::ValidationFailed { object, err } => { + state.errors.insert(object.id(), err.clone()); + } + } + } +} From 7484a10b1722b871b2a90ba161ecf63ff168db2e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:36:34 +0100 Subject: [PATCH 05/27] Refactor to simplify --- crates/fj-core/src/layers/validation.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index e26d4d0a1..b583a98a9 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -75,10 +75,7 @@ pub enum ValidationEvent { impl Event for ValidationEvent { fn evolve(&self, state: &mut Validation) { - match self { - ValidationEvent::ValidationFailed { object, err } => { - state.errors.insert(object.id(), err.clone()); - } - } + let ValidationEvent::ValidationFailed { object, err } = self; + state.errors.insert(object.id(), err.clone()); } } From 310b4372d42bd789a779160f9b8e5378ce39bb51 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:39:03 +0100 Subject: [PATCH 06/27] Simplify `ValidationEvent` --- crates/fj-core/src/layers/validation.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index b583a98a9..dcf130600 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -41,7 +41,7 @@ impl State for Validation { object.validate_with_config(&self.config, &mut errors); for err in errors { - events.push(ValidationEvent::ValidationFailed { + events.push(ValidationEvent { object: object.clone(), err, }); @@ -62,20 +62,16 @@ pub enum ValidationCommand { /// Event produced by `Layer` #[derive(Clone)] -pub enum ValidationEvent { - /// Validation of an object failed - ValidationFailed { - /// The object for which validation failed - object: AnyObject, +pub struct ValidationEvent { + /// The object for which validation failed + pub object: AnyObject, - /// The validation error - err: ValidationError, - }, + /// The validation error + pub err: ValidationError, } impl Event for ValidationEvent { fn evolve(&self, state: &mut Validation) { - let ValidationEvent::ValidationFailed { object, err } = self; - state.errors.insert(object.id(), err.clone()); + state.errors.insert(self.object.id(), self.err.clone()); } } From 3154f997f84473eafdc7d782c912b629f579b835 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:39:18 +0100 Subject: [PATCH 07/27] Update documentation of `ValidationEvent` --- crates/fj-core/src/layers/validation.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index dcf130600..fc4dd30a6 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -60,7 +60,9 @@ pub enum ValidationCommand { }, } -/// Event produced by `Layer` +/// Validation of an object failed +/// +/// Event produced by `Layer`. #[derive(Clone)] pub struct ValidationEvent { /// The object for which validation failed From 5b5a8024050f5fddc875f63c79108d9f5a6cd0ed Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:39:41 +0100 Subject: [PATCH 08/27] Rename `ValidationEvent` to `ValidationFailed` --- crates/fj-core/src/layers/validation.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index fc4dd30a6..056ff718d 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -31,7 +31,7 @@ impl Layer { impl State for Validation { type Command = ValidationCommand; - type Event = ValidationEvent; + type Event = ValidationFailed; fn decide(&self, command: Self::Command, events: &mut Vec) { let mut errors = Vec::new(); @@ -41,7 +41,7 @@ impl State for Validation { object.validate_with_config(&self.config, &mut errors); for err in errors { - events.push(ValidationEvent { + events.push(ValidationFailed { object: object.clone(), err, }); @@ -64,7 +64,7 @@ pub enum ValidationCommand { /// /// Event produced by `Layer`. #[derive(Clone)] -pub struct ValidationEvent { +pub struct ValidationFailed { /// The object for which validation failed pub object: AnyObject, @@ -72,7 +72,7 @@ pub struct ValidationEvent { pub err: ValidationError, } -impl Event for ValidationEvent { +impl Event for ValidationFailed { fn evolve(&self, state: &mut Validation) { state.errors.insert(self.object.id(), self.err.clone()); } From 00b54dc2c5b50a84bde5f5575b6e2652a2fb236d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:41:57 +0100 Subject: [PATCH 09/27] Simplify `ObjectsEvent` --- crates/fj-core/src/layers/objects.rs | 14 +++++--------- crates/fj-core/src/layers/validation.rs | 3 +-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index f3677c933..a2b06974c 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -29,7 +29,7 @@ impl State for Objects { fn decide(&self, command: Self::Command, events: &mut Vec) { let ObjectsCommand::InsertObject { object } = command; - events.push(ObjectsEvent::InsertObject { object }); + events.push(ObjectsEvent { object }); } } @@ -48,17 +48,13 @@ pub enum ObjectsCommand { /// Event produced by `Layer` #[derive(Clone, Debug)] -pub enum ObjectsEvent { - /// Insert an object into the stores - InsertObject { - /// The object to insert - object: AnyObject, - }, +pub struct ObjectsEvent { + /// The object to insert + pub object: AnyObject, } impl Event for ObjectsEvent { fn evolve(&self, state: &mut Objects) { - let ObjectsEvent::InsertObject { object } = self; - object.clone().insert(state); + self.object.clone().insert(state); } } diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 056ff718d..579764902 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -10,9 +10,8 @@ use super::{objects::ObjectsEvent, Event, Layer, State}; impl Layer { /// Handler for [`ObjectsEvent`] pub fn on_objects_event(&mut self, event: ObjectsEvent) { - let ObjectsEvent::InsertObject { object } = event; let command = ValidationCommand::ValidateObject { - object: object.into(), + object: event.object.into(), }; self.process(command, &mut Vec::new()); } From f03cd500d58c6da88943007a22a292fbdaab019e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:42:10 +0100 Subject: [PATCH 10/27] Update documentation of `ObjectsEvent` --- crates/fj-core/src/layers/objects.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index a2b06974c..f5e41611d 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -46,7 +46,9 @@ pub enum ObjectsCommand { }, } -/// Event produced by `Layer` +/// Insert an object into the stores +/// +/// Event produced by `Layer`. #[derive(Clone, Debug)] pub struct ObjectsEvent { /// The object to insert From 7beaa998830305f40afc962deb4298877272da8d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:43:03 +0100 Subject: [PATCH 11/27] Rename `ObjectsEvent` to `InsertObject` --- crates/fj-core/src/layers/objects.rs | 8 ++++---- crates/fj-core/src/layers/validation.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index f5e41611d..25f649f62 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -25,11 +25,11 @@ impl Layer { impl State for Objects { type Command = ObjectsCommand; - type Event = ObjectsEvent; + type Event = InsertObject; fn decide(&self, command: Self::Command, events: &mut Vec) { let ObjectsCommand::InsertObject { object } = command; - events.push(ObjectsEvent { object }); + events.push(InsertObject { object }); } } @@ -50,12 +50,12 @@ pub enum ObjectsCommand { /// /// Event produced by `Layer`. #[derive(Clone, Debug)] -pub struct ObjectsEvent { +pub struct InsertObject { /// The object to insert pub object: AnyObject, } -impl Event for ObjectsEvent { +impl Event for InsertObject { fn evolve(&self, state: &mut Objects) { self.object.clone().insert(state); } diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 579764902..2c05e561c 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -5,11 +5,11 @@ use crate::{ validate::{Validation, ValidationError, ValidationErrors}, }; -use super::{objects::ObjectsEvent, Event, Layer, State}; +use super::{objects::InsertObject, Event, Layer, State}; impl Layer { - /// Handler for [`ObjectsEvent`] - pub fn on_objects_event(&mut self, event: ObjectsEvent) { + /// Handler for [`InsertObject`] + pub fn on_objects_event(&mut self, event: InsertObject) { let command = ValidationCommand::ValidateObject { object: event.object.into(), }; From f088fec63accec05b31b0317005d3b7c68c638a2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 12:09:46 +0100 Subject: [PATCH 12/27] Update method name --- crates/fj-core/src/layers/objects.rs | 2 +- crates/fj-core/src/layers/validation.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index 25f649f62..844909fb4 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -18,7 +18,7 @@ impl Layer { self.process(ObjectsCommand::InsertObject { object }, &mut events); for event in events { - validation.on_objects_event(event); + validation.on_insert_object(event); } } } diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 2c05e561c..984a399bd 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -9,7 +9,7 @@ use super::{objects::InsertObject, Event, Layer, State}; impl Layer { /// Handler for [`InsertObject`] - pub fn on_objects_event(&mut self, event: InsertObject) { + pub fn on_insert_object(&mut self, event: InsertObject) { let command = ValidationCommand::ValidateObject { object: event.object.into(), }; From 2915051e5bc816cd90b697214cd389812b9d2e6a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:48:30 +0100 Subject: [PATCH 13/27] Add `Command` trait --- crates/fj-core/src/layers/layer.rs | 3 +++ crates/fj-core/src/layers/mod.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index 6485fef12..511eb7b9f 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -86,6 +86,9 @@ pub trait State: Sized { fn decide(&self, command: Self::Command, events: &mut Vec); } +/// A command that encodes a request to update a layer's state +pub trait Command {} + /// An event that encodes a change to a layer's state pub trait Event { /// Evolve the provided state diff --git a/crates/fj-core/src/layers/mod.rs b/crates/fj-core/src/layers/mod.rs index 4c78af2ed..d077897fa 100644 --- a/crates/fj-core/src/layers/mod.rs +++ b/crates/fj-core/src/layers/mod.rs @@ -9,6 +9,6 @@ mod layer; mod layers; pub use self::{ - layer::{Event, Layer, State}, + layer::{Command, Event, Layer, State}, layers::Layers, }; From 9555364661c855d7d937b314a9124916923c1e1b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:54:39 +0100 Subject: [PATCH 14/27] Implement `Command` for layer change commands --- crates/fj-core/src/layers/layer.rs | 2 +- crates/fj-core/src/layers/objects.rs | 4 +++- crates/fj-core/src/layers/validation.rs | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index 511eb7b9f..d4d8fd0a3 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -71,7 +71,7 @@ pub trait State: Sized { /// A command that encodes a request to update the state /// /// Commands are processed by [`State::decide`]. - type Command; + type Command: Command; /// An event that encodes a change to the state /// diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index 844909fb4..22a58c138 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -5,7 +5,7 @@ use crate::{ validate::Validation, }; -use super::{Event, Layer, State}; +use super::{Command, Event, Layer, State}; impl Layer { /// Insert and object into the stores @@ -46,6 +46,8 @@ pub enum ObjectsCommand { }, } +impl Command for ObjectsCommand {} + /// Insert an object into the stores /// /// Event produced by `Layer`. diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 984a399bd..90673746f 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -5,7 +5,7 @@ use crate::{ validate::{Validation, ValidationError, ValidationErrors}, }; -use super::{objects::InsertObject, Event, Layer, State}; +use super::{objects::InsertObject, Command, Event, Layer, State}; impl Layer { /// Handler for [`InsertObject`] @@ -59,6 +59,8 @@ pub enum ValidationCommand { }, } +impl Command for ValidationCommand {} + /// Validation of an object failed /// /// Event produced by `Layer`. From 0ae7979ba897fcc73a11930a10bd21fc1dc770d8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 11:58:48 +0100 Subject: [PATCH 15/27] Convert `State::decide` into `Command::decide` --- crates/fj-core/src/layers/layer.rs | 18 +++++++------- crates/fj-core/src/layers/objects.rs | 12 +++++----- crates/fj-core/src/layers/validation.rs | 32 ++++++++++++++----------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index d4d8fd0a3..1ffc0e94a 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -31,7 +31,7 @@ impl Layer { /// The command is processed synchronously. When this method returns, the /// state has been updated. pub fn process(&mut self, command: S::Command, events: &mut Vec) { - self.state.decide(command, events); + command.decide(&self.state, events); for event in events { event.evolve(&mut self.state); @@ -70,25 +70,25 @@ where pub trait State: Sized { /// A command that encodes a request to update the state /// - /// Commands are processed by [`State::decide`]. + /// Commands are processed by [`Command::decide`]. type Command: Command; /// An event that encodes a change to the state /// - /// Events are produced by [`State::decide`] and processed by + /// Events are produced by [`Command::decide`] and processed by /// [`Event::evolve`]. type Event: Event; +} - /// Decide how to react to the provided command +/// A command that encodes a request to update a layer's state +pub trait Command { + /// Decide which events to produce, given the command and provided state /// /// If the command must result in changes to the state, any number of events /// that describe these state changes can be produced. - fn decide(&self, command: Self::Command, events: &mut Vec); + fn decide(self, state: &S, events: &mut Vec); } -/// A command that encodes a request to update a layer's state -pub trait Command {} - /// An event that encodes a change to a layer's state pub trait Event { /// Evolve the provided state @@ -98,6 +98,6 @@ pub trait Event { /// /// Implementations of this method are supposed to be relatively dumb. Any /// decisions that go into updating the state should be made in - /// [`State::decide`], and encoded into the event. + /// [`Command::decide`], and encoded into the event. fn evolve(&self, state: &mut S); } diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index 22a58c138..d45547645 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -26,11 +26,6 @@ impl Layer { impl State for Objects { type Command = ObjectsCommand; type Event = InsertObject; - - fn decide(&self, command: Self::Command, events: &mut Vec) { - let ObjectsCommand::InsertObject { object } = command; - events.push(InsertObject { object }); - } } /// Command for `Layer` @@ -46,7 +41,12 @@ pub enum ObjectsCommand { }, } -impl Command for ObjectsCommand {} +impl Command for ObjectsCommand { + fn decide(self, _: &Objects, events: &mut Vec<::Event>) { + let ObjectsCommand::InsertObject { object } = self; + events.push(InsertObject { object }); + } +} /// Insert an object into the stores /// diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 90673746f..618fd1b07 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -31,13 +31,28 @@ impl Layer { impl State for Validation { type Command = ValidationCommand; type Event = ValidationFailed; +} + +/// Command for `Layer` +pub enum ValidationCommand { + /// Validate the provided object + ValidateObject { + /// The object to validate + object: AnyObject, + }, +} - fn decide(&self, command: Self::Command, events: &mut Vec) { +impl Command for ValidationCommand { + fn decide( + self, + state: &Validation, + events: &mut Vec<::Event>, + ) { let mut errors = Vec::new(); - match command { + match self { ValidationCommand::ValidateObject { object } => { - object.validate_with_config(&self.config, &mut errors); + object.validate_with_config(&state.config, &mut errors); for err in errors { events.push(ValidationFailed { @@ -50,17 +65,6 @@ impl State for Validation { } } -/// Command for `Layer` -pub enum ValidationCommand { - /// Validate the provided object - ValidateObject { - /// The object to validate - object: AnyObject, - }, -} - -impl Command for ValidationCommand {} - /// Validation of an object failed /// /// Event produced by `Layer`. From 39edbab8218d5424fc01fe6277927f0578246db0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 12:01:43 +0100 Subject: [PATCH 16/27] Move `State::Event` to `Command` --- crates/fj-core/src/layers/layer.rs | 16 ++++++++++------ crates/fj-core/src/layers/objects.rs | 5 +++-- crates/fj-core/src/layers/validation.rs | 9 +++------ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index 1ffc0e94a..e91412ab6 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -30,7 +30,11 @@ impl Layer { /// /// The command is processed synchronously. When this method returns, the /// state has been updated. - pub fn process(&mut self, command: S::Command, events: &mut Vec) { + pub fn process( + &mut self, + command: S::Command, + events: &mut Vec<>::Event>, + ) { command.decide(&self.state, events); for event in events { @@ -72,21 +76,21 @@ pub trait State: Sized { /// /// Commands are processed by [`Command::decide`]. type Command: Command; +} +/// A command that encodes a request to update a layer's state +pub trait Command { /// An event that encodes a change to the state /// /// Events are produced by [`Command::decide`] and processed by /// [`Event::evolve`]. - type Event: Event; -} + type Event: Event; -/// A command that encodes a request to update a layer's state -pub trait Command { /// Decide which events to produce, given the command and provided state /// /// If the command must result in changes to the state, any number of events /// that describe these state changes can be produced. - fn decide(self, state: &S, events: &mut Vec); + fn decide(self, state: &S, events: &mut Vec); } /// An event that encodes a change to a layer's state diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index d45547645..b18c012fd 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -25,7 +25,6 @@ impl Layer { impl State for Objects { type Command = ObjectsCommand; - type Event = InsertObject; } /// Command for `Layer` @@ -42,7 +41,9 @@ pub enum ObjectsCommand { } impl Command for ObjectsCommand { - fn decide(self, _: &Objects, events: &mut Vec<::Event>) { + type Event = InsertObject; + + fn decide(self, _: &Objects, events: &mut Vec) { let ObjectsCommand::InsertObject { object } = self; events.push(InsertObject { object }); } diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 618fd1b07..52ee9f62d 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -30,7 +30,6 @@ impl Layer { impl State for Validation { type Command = ValidationCommand; - type Event = ValidationFailed; } /// Command for `Layer` @@ -43,11 +42,9 @@ pub enum ValidationCommand { } impl Command for ValidationCommand { - fn decide( - self, - state: &Validation, - events: &mut Vec<::Event>, - ) { + type Event = ValidationFailed; + + fn decide(self, state: &Validation, events: &mut Vec) { let mut errors = Vec::new(); match self { From 2400b666810d6087f94335e0e7097e913db09012 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 12:03:10 +0100 Subject: [PATCH 17/27] Refactor to simplify --- crates/fj-core/src/layers/layer.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index e91412ab6..f6fed4077 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -30,11 +30,10 @@ impl Layer { /// /// The command is processed synchronously. When this method returns, the /// state has been updated. - pub fn process( - &mut self, - command: S::Command, - events: &mut Vec<>::Event>, - ) { + pub fn process(&mut self, command: C, events: &mut Vec) + where + C: Command, + { command.decide(&self.state, events); for event in events { From 8cd1caa4c89162addb12e765f80a9b7ec38d7440 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 12:03:20 +0100 Subject: [PATCH 18/27] Remove redundant associated type --- crates/fj-core/src/layers/layer.rs | 7 +------ crates/fj-core/src/layers/objects.rs | 4 +--- crates/fj-core/src/layers/validation.rs | 4 +--- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index f6fed4077..a0dc348e9 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -70,12 +70,7 @@ where /// the consumer of this trait's API. /// /// See [`Layer`] for a more detailed explanation. -pub trait State: Sized { - /// A command that encodes a request to update the state - /// - /// Commands are processed by [`Command::decide`]. - type Command: Command; -} +pub trait State: Sized {} /// A command that encodes a request to update a layer's state pub trait Command { diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index b18c012fd..d18c863ff 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -23,9 +23,7 @@ impl Layer { } } -impl State for Objects { - type Command = ObjectsCommand; -} +impl State for Objects {} /// Command for `Layer` #[derive(Debug)] diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 52ee9f62d..70649f029 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -28,9 +28,7 @@ impl Layer { } } -impl State for Validation { - type Command = ValidationCommand; -} +impl State for Validation {} /// Command for `Layer` pub enum ValidationCommand { From 8bd5e990deb549373b7297c7d744aff21bb01d5f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 12:04:36 +0100 Subject: [PATCH 19/27] Remove redundant trait bound --- crates/fj-core/src/layers/layer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index a0dc348e9..d905e4e00 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -73,7 +73,7 @@ where pub trait State: Sized {} /// A command that encodes a request to update a layer's state -pub trait Command { +pub trait Command { /// An event that encodes a change to the state /// /// Events are produced by [`Command::decide`] and processed by From e38716a022309dce6e5f1b9f4dab079fe2c57a52 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 12:04:48 +0100 Subject: [PATCH 20/27] Remove redundant trait bounds --- crates/fj-core/src/layers/layer.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index d905e4e00..7e55fd658 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -16,11 +16,11 @@ use std::ops::Deref; /// This design takes inspiration from, and uses the nomenclature of, this /// article: /// -pub struct Layer { +pub struct Layer { state: S, } -impl Layer { +impl Layer { /// Create an instance of `Layer` pub fn new(state: S) -> Self { Self { state } @@ -47,7 +47,7 @@ impl Layer { } } -impl Deref for Layer { +impl Deref for Layer { type Target = S; fn deref(&self) -> &Self::Target { @@ -55,7 +55,7 @@ impl Deref for Layer { } } -impl Default for Layer +impl Default for Layer where S: Default, { From dd499594e08043749eafbf910128dc8842a41e1e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 12:05:07 +0100 Subject: [PATCH 21/27] Remove redundant trait --- crates/fj-core/src/layers/layer.rs | 11 ----------- crates/fj-core/src/layers/mod.rs | 2 +- crates/fj-core/src/layers/objects.rs | 4 +--- crates/fj-core/src/layers/validation.rs | 4 +--- 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index 7e55fd658..edbdcc48b 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -10,9 +10,6 @@ use std::ops::Deref; /// processed by [`Layer::process`]. Processing a command can result in any /// number of events, which can then be used as commands for other layers. /// -/// All of this is mediated through [`State`], which the wrapped state must -/// implement. -/// /// This design takes inspiration from, and uses the nomenclature of, this /// article: /// @@ -64,14 +61,6 @@ where } } -/// The state of a specific layer -/// -/// Implementations of this trait are wrapped by the generic [`Layer`], which is -/// the consumer of this trait's API. -/// -/// See [`Layer`] for a more detailed explanation. -pub trait State: Sized {} - /// A command that encodes a request to update a layer's state pub trait Command { /// An event that encodes a change to the state diff --git a/crates/fj-core/src/layers/mod.rs b/crates/fj-core/src/layers/mod.rs index d077897fa..d18457b73 100644 --- a/crates/fj-core/src/layers/mod.rs +++ b/crates/fj-core/src/layers/mod.rs @@ -9,6 +9,6 @@ mod layer; mod layers; pub use self::{ - layer::{Command, Event, Layer, State}, + layer::{Command, Event, Layer}, layers::Layers, }; diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index d18c863ff..3319eac02 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -5,7 +5,7 @@ use crate::{ validate::Validation, }; -use super::{Command, Event, Layer, State}; +use super::{Command, Event, Layer}; impl Layer { /// Insert and object into the stores @@ -23,8 +23,6 @@ impl Layer { } } -impl State for Objects {} - /// Command for `Layer` #[derive(Debug)] pub enum ObjectsCommand { diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 70649f029..7f670d5b8 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -5,7 +5,7 @@ use crate::{ validate::{Validation, ValidationError, ValidationErrors}, }; -use super::{objects::InsertObject, Command, Event, Layer, State}; +use super::{objects::InsertObject, Command, Event, Layer}; impl Layer { /// Handler for [`InsertObject`] @@ -28,8 +28,6 @@ impl Layer { } } -impl State for Validation {} - /// Command for `Layer` pub enum ValidationCommand { /// Validate the provided object From 3e3c49eafaa473baa40e135969866b1559c755cc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 12:13:40 +0100 Subject: [PATCH 22/27] Refactor to simplify --- crates/fj-core/src/layers/validation.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 7f670d5b8..6b1572571 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -43,17 +43,15 @@ impl Command for ValidationCommand { fn decide(self, state: &Validation, events: &mut Vec) { let mut errors = Vec::new(); - match self { - ValidationCommand::ValidateObject { object } => { - object.validate_with_config(&state.config, &mut errors); + let ValidationCommand::ValidateObject { object } = self; - for err in errors { - events.push(ValidationFailed { - object: object.clone(), - err, - }); - } - } + object.validate_with_config(&state.config, &mut errors); + + for err in errors { + events.push(ValidationFailed { + object: object.clone(), + err, + }); } } } From 01247c3d9ab3018094817f2d05ef122b04cbb7b5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 12:15:18 +0100 Subject: [PATCH 23/27] Remove redundant command --- crates/fj-core/src/layers/validation.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 6b1572571..0f34f5002 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -10,9 +10,7 @@ use super::{objects::InsertObject, Command, Event, Layer}; impl Layer { /// Handler for [`InsertObject`] pub fn on_insert_object(&mut self, event: InsertObject) { - let command = ValidationCommand::ValidateObject { - object: event.object.into(), - }; + let command = event; self.process(command, &mut Vec::new()); } @@ -28,23 +26,13 @@ impl Layer { } } -/// Command for `Layer` -pub enum ValidationCommand { - /// Validate the provided object - ValidateObject { - /// The object to validate - object: AnyObject, - }, -} - -impl Command for ValidationCommand { +impl Command for InsertObject { type Event = ValidationFailed; fn decide(self, state: &Validation, events: &mut Vec) { let mut errors = Vec::new(); - let ValidationCommand::ValidateObject { object } = self; - + let object: AnyObject = self.object.into(); object.validate_with_config(&state.config, &mut errors); for err in errors { From bf633a60ac463a609a885f3f3b10d6edd45e4629 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 12:15:31 +0100 Subject: [PATCH 24/27] Inline redundant variable --- crates/fj-core/src/layers/validation.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 0f34f5002..877ef6644 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -10,8 +10,7 @@ use super::{objects::InsertObject, Command, Event, Layer}; impl Layer { /// Handler for [`InsertObject`] pub fn on_insert_object(&mut self, event: InsertObject) { - let command = event; - self.process(command, &mut Vec::new()); + self.process(event, &mut Vec::new()); } /// Consume the validation layer, returning any validation errors From 0e5ab8dcb3ff753a57e479fc89056288b511d231 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 12:16:11 +0100 Subject: [PATCH 25/27] Inline redundant method --- crates/fj-core/src/layers/objects.rs | 2 +- crates/fj-core/src/layers/validation.rs | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index 3319eac02..d4e6badc0 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -18,7 +18,7 @@ impl Layer { self.process(ObjectsCommand::InsertObject { object }, &mut events); for event in events { - validation.on_insert_object(event); + validation.process(event, &mut Vec::new()); } } } diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 877ef6644..96071ee9e 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -8,11 +8,6 @@ use crate::{ use super::{objects::InsertObject, Command, Event, Layer}; impl Layer { - /// Handler for [`InsertObject`] - pub fn on_insert_object(&mut self, event: InsertObject) { - self.process(event, &mut Vec::new()); - } - /// Consume the validation layer, returning any validation errors pub fn into_result(self) -> Result<(), ValidationErrors> { let errors = self.into_state().into_errors(); From 421bdb96a738b5e496babd7271493092848a4281 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 12:18:09 +0100 Subject: [PATCH 26/27] Remove redundant command --- crates/fj-core/src/layers/objects.rs | 32 ++++++++-------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index d4e6badc0..121d60dc2 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -15,7 +15,7 @@ impl Layer { validation: &mut Layer, ) { let mut events = Vec::new(); - self.process(ObjectsCommand::InsertObject { object }, &mut events); + self.process(InsertObject { object }, &mut events); for event in events { validation.process(event, &mut Vec::new()); @@ -23,28 +23,6 @@ impl Layer { } } -/// Command for `Layer` -#[derive(Debug)] -pub enum ObjectsCommand { - /// Insert an object into the stores - /// - /// This is the one primitive operation that all other operations are built - /// upon. - InsertObject { - /// The object to insert - object: AnyObject, - }, -} - -impl Command for ObjectsCommand { - type Event = InsertObject; - - fn decide(self, _: &Objects, events: &mut Vec) { - let ObjectsCommand::InsertObject { object } = self; - events.push(InsertObject { object }); - } -} - /// Insert an object into the stores /// /// Event produced by `Layer`. @@ -54,6 +32,14 @@ pub struct InsertObject { pub object: AnyObject, } +impl Command for InsertObject { + type Event = InsertObject; + + fn decide(self, _: &Objects, events: &mut Vec) { + events.push(self); + } +} + impl Event for InsertObject { fn evolve(&self, state: &mut Objects) { self.object.clone().insert(state); From b4e6e0717ddea6016cdbf3745b80d31b3020d468 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Feb 2024 12:17:08 +0100 Subject: [PATCH 27/27] Update documentation of `layers` --- crates/fj-core/src/layers/layer.rs | 4 ++-- crates/fj-core/src/layers/layers.rs | 2 +- crates/fj-core/src/layers/objects.rs | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index edbdcc48b..4f4148a9a 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -80,8 +80,8 @@ pub trait Command { pub trait Event { /// Evolve the provided state /// - /// This is the only method that gets mutable access to the state, making - /// sure that all changes to the state are captured as events. + /// This is the only method that [`Layer`] gives mutable access to the + /// state, making sure that all changes to the state are captured as events. /// /// Implementations of this method are supposed to be relatively dumb. Any /// decisions that go into updating the state should be made in diff --git a/crates/fj-core/src/layers/layers.rs b/crates/fj-core/src/layers/layers.rs index 2682537a8..200fd4529 100644 --- a/crates/fj-core/src/layers/layers.rs +++ b/crates/fj-core/src/layers/layers.rs @@ -21,7 +21,7 @@ use super::Layer; /// That can be changed, once necessary. #[derive(Default)] pub struct Layers { - /// The objects layers + /// The objects layer /// /// Manages the stores of topological and geometric objects that make up /// shapes. diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index 121d60dc2..b5cff0ea2 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -8,7 +8,9 @@ use crate::{ use super::{Command, Event, Layer}; impl Layer { - /// Insert and object into the stores + /// Insert an object into the stores + /// + /// Passes any events produced to the validation layer. pub fn insert( &mut self, object: AnyObject, @@ -25,7 +27,8 @@ impl Layer { /// Insert an object into the stores /// -/// Event produced by `Layer`. +/// This struct serves as both event and command for `Layer`, as well +/// as a command for `Layer`. #[derive(Clone, Debug)] pub struct InsertObject { /// The object to insert