Skip to content

Commit

Permalink
Add Services::drop_and_validate
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Jun 26, 2023
1 parent 1ce1670 commit 7f39c59
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion crates/fj-core/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ mod objects;
mod service;
mod validation;

use crate::objects::{Object, ObjectSet, Objects, WithHandle};
use crate::{
objects::{Object, ObjectSet, Objects, WithHandle},
validate::ValidationErrors,
};

pub use self::{
objects::{InsertObject, Operation},
Expand Down Expand Up @@ -61,6 +64,19 @@ impl Services {
self.validation
.execute(ValidationCommand::OnlyValidate { objects }, &mut events);
}

/// Drop `Services`; return any unhandled validation error
pub fn drop_and_validate(self) -> Result<(), ValidationErrors> {
let errors = ValidationErrors(
self.validation.errors.values().cloned().collect(),
);

if errors.0.is_empty() {
Ok(())
} else {
Err(errors)
}
}
}

impl Default for Services {
Expand Down

0 comments on commit 7f39c59

Please sign in to comment.