Skip to main content

shacl_ir/components/
or.rs

1use crate::shape_label_idx::ShapeLabelIdx;
2use std::fmt::Display;
3
4/// sh:or specifies the condition that each value node conforms to at least one
5/// of the provided shapes. This is comparable to disjunction and the logical
6/// "or" operator.
7///
8/// https://www.w3.org/TR/shacl/#AndConstraintComponent
9
10#[derive(Debug, Clone)]
11pub struct Or {
12    shapes: Vec<ShapeLabelIdx>,
13}
14
15impl Or {
16    pub fn new(shapes: Vec<ShapeLabelIdx>) -> Self {
17        Or { shapes }
18    }
19
20    pub fn shapes(&self) -> &Vec<ShapeLabelIdx> {
21        &self.shapes
22    }
23}
24
25impl Display for Or {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        write!(
28            f,
29            "Or[{}]",
30            self.shapes()
31                .iter()
32                .map(|s| s.to_string())
33                .collect::<Vec<_>>()
34                .join(", ")
35        )
36    }
37}