Skip to content

Commit

Permalink
Prepare for more types of validation events
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed May 2, 2023
1 parent 10aeba2 commit 42d3555
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::objects::{Object, Objects, WithHandle};
pub use self::{
objects::{InsertObject, Operation},
service::{Service, State},
validation::{Validation, ValidationCommand, ValidationFailed},
validation::{Validation, ValidationCommand, ValidationEvent},
};

/// The kernel services
Expand Down
23 changes: 15 additions & 8 deletions crates/fj-kernel/src/services/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Drop for Validation {

impl State for Validation {
type Command = ValidationCommand;
type Event = ValidationFailed;
type Event = ValidationEvent;

fn decide(&self, command: Self::Command, events: &mut Vec<Self::Event>) {
let ValidationCommand::ValidateObject { object } = command;
Expand All @@ -45,15 +45,19 @@ impl State for Validation {
object.validate(&mut errors);

for err in errors {
events.push(ValidationFailed {
events.push(ValidationEvent::ValidationFailed {
object: object.clone(),
err,
});
}
}

fn evolve(&mut self, event: &Self::Event) {
self.errors.insert(event.object.id(), event.err.clone());
match event {
ValidationEvent::ValidationFailed { object, err } => {
self.errors.insert(object.id(), err.clone());
}
}
}
}

Expand All @@ -68,10 +72,13 @@ pub enum ValidationCommand {

/// The event produced by the validation service
#[derive(Clone)]
pub struct ValidationFailed {
/// The object for which validation failed
pub object: Object<BehindHandle>,
pub enum ValidationEvent {
/// Validation of an object failed
ValidationFailed {
/// The object for which validation failed
object: Object<BehindHandle>,

/// The validation error
pub err: ValidationError,
/// The validation error
err: ValidationError,
},
}

0 comments on commit 42d3555

Please sign in to comment.