Skip to main content

shacl_ir/components/
and.rs

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