shacl_ast/ast/
shape.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
31
32
33
34
35
36
use srdf::SRDFBuilder;
use std::fmt::Display;

use crate::{node_shape::NodeShape, property_shape::PropertyShape};

#[derive(Debug, Clone)]
pub enum Shape {
    NodeShape(Box<NodeShape>),
    PropertyShape(PropertyShape),
}

impl Shape {
    pub fn write<RDF>(&self, rdf: &mut RDF) -> Result<(), RDF::Err>
    where
        RDF: SRDFBuilder,
    {
        match self {
            Shape::NodeShape(ns) => {
                ns.write(rdf)?;
            }
            Shape::PropertyShape(ps) => {
                ps.write(rdf)?;
            }
        }
        Ok(())
    }
}

impl Display for Shape {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match &self {
            Shape::NodeShape(ns) => write!(f, "{ns}"),
            Shape::PropertyShape(ps) => write!(f, "{ps}"),
        }
    }
}