specler/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#![warn(missing_docs)]

//! # Specler
//!
//! A simple library for defining and validating specifications on your types.
//! This solves an issue with other validation approaches where
//! it is possible to first create a type and then verify its validity.
//! In disagreeing with this approach, a solution was needed to
//! verify specifications in factory methods.
//!
//! ## Concepts
//!
//! A specification defines a list of requirements that a type must meet.
//! These requirements are expressed as a list of validators, which are
//! simple functions returning a `ValidatorResult`. These then get
//! compiled into a single `SpecValidationResult`.
//!
//! ## Examples
//!
//! ### Validating using an empty spec
//!
//! ```
//! use specler::assert_spec_valid;
//! use crate::specler::core::require::Require;
//! use crate::specler::core::spec::spec_validation_result::SpecValidationResult;
//!
//! let spec = Require::<String>::to();
//! let result = spec.validate("");
//!
//! assert_spec_valid!(result);
//! ```
//!
//! ### Validating a string to not be empty
//!
//! ```
//! use specler::{assert_spec_invalid, assert_spec_validation_error};
//! use specler::core::require::Require;
//! use specler::specs::string::not_empty;
//! use crate::specler::core::spec::spec_validation_result::SpecValidationResult;
//!
//! let spec = Require::<String>::to().be(not_empty);
//! let result = spec.validate("");
//!
//! assert_spec_invalid!(result);
//! assert_spec_validation_error!(result, "String cannot be empty");
//! ```

/// Core module containing core functionality, excluding concrete type specifications
pub mod core;

/// Module containing core specifications for standard types, e.g. String
pub mod specs;