shex_ast/compiled/
node_constraint.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 crate::{ast::NodeConstraint as AstNodeConstraint, Cond};
use std::fmt::Display;

/// Represents compiled node constraints
#[derive(Debug, PartialEq, Clone)]
pub struct NodeConstraint {
    source: AstNodeConstraint,
    cond: Cond,
    display: String,
}

impl NodeConstraint {
    pub fn new(nc: AstNodeConstraint, cond: Cond, display: String) -> Self {
        NodeConstraint {
            source: nc,
            cond,
            display,
        }
    }

    pub fn cond(&self) -> Cond {
        self.cond.clone()
    }
}

impl Display for NodeConstraint {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.display)
    }
}