mirror of https://github.com/hannobraun/Fornjot
Remove old validation infrastructure
This commit is contained in:
parent
09fbd74ee1
commit
e996929061
|
@ -31,62 +31,10 @@ pub use self::{
|
||||||
vertex::{SurfaceVertexValidationError, VertexValidationError},
|
vertex::{SurfaceVertexValidationError, VertexValidationError},
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{convert::Infallible, ops::Deref};
|
use std::convert::Infallible;
|
||||||
|
|
||||||
use fj_math::Scalar;
|
use fj_math::Scalar;
|
||||||
|
|
||||||
use crate::iter::ObjectIters;
|
|
||||||
|
|
||||||
/// Validate an object
|
|
||||||
pub trait Validate: Sized {
|
|
||||||
/// Validate the object using default configuration
|
|
||||||
///
|
|
||||||
/// The following calls are equivalent:
|
|
||||||
/// ``` rust
|
|
||||||
/// # use fj_kernel::{
|
|
||||||
/// # objects::{GlobalVertex, Objects},
|
|
||||||
/// # validate::{Validate, ValidationConfig},
|
|
||||||
/// # };
|
|
||||||
/// # let objects = Objects::new();
|
|
||||||
/// # let object = objects.global_vertices.insert(
|
|
||||||
/// # GlobalVertex::from_position([0., 0., 0.])
|
|
||||||
/// # );
|
|
||||||
/// object.validate();
|
|
||||||
/// ```
|
|
||||||
/// ``` rust
|
|
||||||
/// # use fj_kernel::{
|
|
||||||
/// # objects::{GlobalVertex, Objects},
|
|
||||||
/// # validate::{Validate, ValidationConfig},
|
|
||||||
/// # };
|
|
||||||
/// # let objects = Objects::new();
|
|
||||||
/// # let object = objects.global_vertices.insert(
|
|
||||||
/// # GlobalVertex::from_position([0., 0., 0.])
|
|
||||||
/// # );
|
|
||||||
/// object.validate_with_config(&ValidationConfig::default());
|
|
||||||
/// ```
|
|
||||||
fn validate(self) -> Result<Validated<Self>, ValidationError> {
|
|
||||||
self.validate_with_config(&ValidationConfig::default())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Validate the object
|
|
||||||
fn validate_with_config(
|
|
||||||
self,
|
|
||||||
config: &ValidationConfig,
|
|
||||||
) -> Result<Validated<Self>, ValidationError>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Validate for T
|
|
||||||
where
|
|
||||||
T: for<'r> ObjectIters<'r>,
|
|
||||||
{
|
|
||||||
fn validate_with_config(
|
|
||||||
self,
|
|
||||||
_: &ValidationConfig,
|
|
||||||
) -> Result<Validated<Self>, ValidationError> {
|
|
||||||
Ok(Validated(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Validate an object
|
/// Validate an object
|
||||||
pub trait Validate2: Sized {
|
pub trait Validate2: Sized {
|
||||||
/// The error that validation of the implementing type can result in
|
/// The error that validation of the implementing type can result in
|
||||||
|
@ -136,27 +84,6 @@ impl Default for ValidationConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wrapper around an object that indicates the object has been validated
|
|
||||||
///
|
|
||||||
/// Returned by implementations of `Validate`.
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
|
||||||
pub struct Validated<T>(T);
|
|
||||||
|
|
||||||
impl<T> Validated<T> {
|
|
||||||
/// Consume this instance of `Validated` and return the wrapped object
|
|
||||||
pub fn into_inner(self) -> T {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Deref for Validated<T> {
|
|
||||||
type Target = T;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An error that can occur during a validation
|
/// An error that can occur during a validation
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
|
Loading…
Reference in New Issue