Skip to main content

shacl_ir/components/
in_component.rs

1use rudof_rdf::rdf_core::term::Object;
2use std::fmt::Display;
3
4/// sh:in specifies the condition that each value node is a member of a provided
5/// SHACL list.
6///
7/// https://www.w3.org/TR/shacl/#InConstraintComponent
8#[derive(Debug, Clone)]
9pub struct In {
10    values: Vec<Object>,
11}
12
13impl In {
14    pub fn new(values: Vec<Object>) -> Self {
15        In { values }
16    }
17
18    pub fn values(&self) -> &Vec<Object> {
19        &self.values
20    }
21}
22
23impl Display for In {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        let values = self
26            .values()
27            .iter()
28            .map(|v| v.to_string())
29            .collect::<Vec<_>>()
30            .join(", ");
31        write!(f, "In: [{values}]")
32    }
33}