Add `CycleValidationError`

This commit is contained in:
Hanno Braun 2022-11-01 14:02:22 +01:00
parent b121f8a1e9
commit 7671353c50
3 changed files with 16 additions and 6 deletions

View File

@ -103,8 +103,8 @@ use crate::{
path::GlobalPath,
storage::{Handle, Store},
validate::{
HalfEdgeValidationError, SurfaceVertexValidationError, Validate2,
VertexValidationError,
CycleValidationError, HalfEdgeValidationError,
SurfaceVertexValidationError, Validate2, VertexValidationError,
},
};
@ -187,7 +187,10 @@ pub struct Cycles {
impl Cycles {
/// Insert a [`Cycle`] into the store
pub fn insert(&self, cycle: Cycle) -> Result<Handle<Cycle>, Infallible> {
pub fn insert(
&self,
cycle: Cycle,
) -> Result<Handle<Cycle>, CycleValidationError> {
cycle.validate()?;
Ok(self.store.insert(cycle))
}

View File

@ -1,11 +1,9 @@
use std::convert::Infallible;
use crate::objects::Cycle;
use super::{Validate2, ValidationConfig};
impl Validate2 for Cycle {
type Error = Infallible;
type Error = CycleValidationError;
fn validate_with_config(
&self,
@ -14,3 +12,7 @@ impl Validate2 for Cycle {
Ok(())
}
}
/// [`Cycle`] validation error
#[derive(Debug, thiserror::Error)]
pub enum CycleValidationError {}

View File

@ -26,6 +26,7 @@ mod uniqueness;
mod vertex;
pub use self::{
cycle::CycleValidationError,
edge::HalfEdgeValidationError,
uniqueness::UniquenessIssues,
vertex::{SurfaceVertexValidationError, VertexValidationError},
@ -177,6 +178,10 @@ pub enum ValidationError {
#[error("Uniqueness validation failed")]
Uniqueness(#[from] UniquenessIssues),
/// `Cycle` validation error
#[error(transparent)]
Cycle(#[from] CycleValidationError),
/// `HalfEdge` validation error
#[error(transparent)]
HalfEdge(#[from] HalfEdgeValidationError),