shex_validation/
reason.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
use std::fmt::Display;

use shex_ast::{
    compiled::{node_constraint::NodeConstraint, shape::Shape, shape_expr::ShapeExpr},
    Node,
};

/// Reason represents justifications about why a node conforms to some shape
#[derive(Debug, Clone)]
pub enum Reason {
    NodeConstraintPassed { node: Node, nc: NodeConstraint },
    ShapeAndPassed { node: Node, se: ShapeExpr },
    ShapePassed { node: Node, shape: Shape },
}

impl Display for Reason {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Reason::NodeConstraintPassed { node, nc } => {
                write!(f, "Node constraint passed. Node: {node}, Constraint: {nc}",)
            }
            Reason::ShapeAndPassed { node, se } => {
                write!(f, "AND passed. Node {node}, and: {se}")
            }
            Reason::ShapePassed { node, shape } => {
                write!(f, "Shape passed. Node {node}, shape: {shape}")
            }
        }
    }
}