use turnframe_core::error::DomainRejection;
use turnframe_core::understanding::UnderstoodAct;
pub trait ActChecker: Send + Sync {
fn check(&self, act: &UnderstoodAct) -> Result<(), DomainRejection>;
fn is_active(&self) -> bool {
true
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct NoChecks;
impl ActChecker for NoChecks {
fn check(&self, _act: &UnderstoodAct) -> Result<(), DomainRejection> {
Ok(())
}
fn is_active(&self) -> bool {
false
}
}
pub(crate) fn argument_of(rejection: &DomainRejection) -> Option<String> {
let pointer = rejection.argument.as_deref()?;
let name = pointer.trim_start_matches('/').split('/').next()?;
(!name.is_empty()).then(|| name.replace("~1", "/").replace("~0", "~"))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_pointer_names_its_first_segment() {
let rejection = DomainRejection::new("too_long", "k").on_argument("/value/0");
assert_eq!(argument_of(&rejection).as_deref(), Some("value"));
assert_eq!(argument_of(&DomainRejection::new("x", "k")), None);
}
}