Expand description
§koruma
koruma is a per-field validation framework focused on:
- Type Safety: Strongly typed validation error structs generated at compile time.
- Ergonomics: Derive macros and validator attributes that minimize boilerplate.
- Developer Experience: Optional constructors, nested/newtype validation, and fluent/i18n.
§koruma-collection
A curated set of validators built on top of koruma, organized by domain:
string, format, numeric, collection, and general-purpose validators.
§Quick Start
use koruma::{Koruma, Validate, validator};
#[validator]
#[derive(Clone, Debug)]
pub struct RangeValidation<T> {
pub min: T,
pub max: T,
#[koruma(value)]
pub actual: T,
}
impl<T: PartialOrd + Clone> Validate<T> for RangeValidation<T> {
fn validate(&self, value: &T) -> bool {
*value >= self.min && *value <= self.max
}
}
#[derive(Koruma)]
pub struct User {
#[koruma(RangeValidation::<_>(min = 0, max = 150))]
pub age: i32,
}
let user = User { age: 200 };
let err = user.validate().unwrap_err();
if let Some(range_err) = err.age().range_validation() {
println!("age out of range: {}", range_err.actual);
}§Fluent/i18n
Enable the fluent feature and derive EsFluent on validators for localized messages. Use
KorumaAllFluent to format all() results, and koruma-collection with full-fluent to get
built-in validators plus translations.
§Examples
Traits§
- Builder
With Value - Trait for validator builders that can receive the value being validated.
- Newtype
Validation - Marker trait for newtype structs (single-field wrappers) that derive
Koruma. - Validate
- Trait for types that can validate a value of type
T. - Validate
Ext - Trait for structs that derive
Korumaand have avalidate()method. - Validation
Error - Trait for validation error structs that have no errors.
Attribute Macros§
- validator
- Attribute macro for validator structs.
Derive Macros§
- Koruma
- Derive macro for generating validation error structs and validate methods.
- Koruma
AllDisplay - Derive macro for implementing
Displayon theall()validator enums. - Koruma
AllFluent - Derive macro for implementing
ToFluentStringon theall()validator enums.