Skip to main content

shacl_ir/components/
xone.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/#XoneConstraintComponent
9#[derive(Debug, Clone)]
10pub struct Xone {
11    shapes: Vec<ShapeLabelIdx>,
12}
13
14impl Xone {
15    pub fn new(shapes: Vec<ShapeLabelIdx>) -> Self {
16        Xone { shapes }
17    }
18
19    pub fn shapes(&self) -> &Vec<ShapeLabelIdx> {
20        &self.shapes
21    }
22}
23
24impl Display for Xone {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        write!(
27            f,
28            "Xone [{}]",
29            self.shapes()
30                .iter()
31                .map(|s| s.to_string())
32                .collect::<Vec<_>>()
33                .join(", ")
34        )
35    }
36}