turnframe_understand/
check.rs1use turnframe_core::error::DomainRejection;
4use turnframe_core::understanding::UnderstoodAct;
5
6pub trait ActChecker: Send + Sync {
12 fn check(&self, act: &UnderstoodAct) -> Result<(), DomainRejection>;
18
19 fn is_active(&self) -> bool {
21 true
22 }
23}
24
25#[derive(Debug, Clone, Copy, Default)]
27pub struct NoChecks;
28
29impl ActChecker for NoChecks {
30 fn check(&self, _act: &UnderstoodAct) -> Result<(), DomainRejection> {
31 Ok(())
32 }
33
34 fn is_active(&self) -> bool {
35 false
36 }
37}
38
39pub(crate) fn argument_of(rejection: &DomainRejection) -> Option<String> {
41 let pointer = rejection.argument.as_deref()?;
42 let name = pointer.trim_start_matches('/').split('/').next()?;
43 (!name.is_empty()).then(|| name.replace("~1", "/").replace("~0", "~"))
44}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn a_pointer_names_its_first_segment() {
52 let rejection = DomainRejection::new("too_long", "k").on_argument("/value/0");
53 assert_eq!(argument_of(&rejection).as_deref(), Some("value"));
54 assert_eq!(argument_of(&DomainRejection::new("x", "k")), None);
55 }
56}