#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Violation {
pub property_path: String,
pub message: String,
pub code: &'static str,
}
impl Violation {
#[must_use]
pub fn new(
property_path: impl Into<String>,
message: impl Into<String>,
code: &'static str,
) -> Self {
Self {
property_path: property_path.into(),
message: message.into(),
code,
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ConstraintViolationList {
items: Vec<Violation>,
}
impl ConstraintViolationList {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn add(&mut self, violation: Violation) {
self.items.push(violation);
}
#[must_use]
pub const fn is_empty(&self) -> bool {
self.items.is_empty()
}
#[must_use]
pub const fn len(&self) -> usize {
self.items.len()
}
#[must_use]
pub fn as_slice(&self) -> &[Violation] {
&self.items
}
}