shapemap/
shape_selector.rs

1use prefixmap::IriRef;
2use serde::Serialize;
3use shex_ast::ShapeExprLabel;
4
5/// A ShapeSelector following [ShapeMap spec](https://shexspec.github.io/shape-map/#shapemap-structure) can be used to select shape expressions to validate
6///
7#[derive(Debug, PartialEq, Clone, Serialize)]
8pub enum ShapeSelector {
9    Label(ShapeExprLabel),
10    Start,
11}
12
13impl ShapeSelector {
14    pub fn iri_unchecked(str: &str) -> ShapeSelector {
15        ShapeSelector::Label(ShapeExprLabel::iri_unchecked(str))
16    }
17
18    pub fn iri_ref(iri: IriRef) -> ShapeSelector {
19        ShapeSelector::Label(ShapeExprLabel::iri_ref(iri))
20    }
21
22    pub fn start() -> ShapeSelector {
23        ShapeSelector::Start
24    }
25
26    pub fn prefixed(alias: &str, local: &str) -> Self {
27        ShapeSelector::Label(ShapeExprLabel::prefixed(alias, local))
28    }
29
30    pub fn iter_shape(&self) -> impl Iterator<Item = &ShapeExprLabel> {
31        match self {
32            ShapeSelector::Label(label) => std::iter::once(label),
33            ShapeSelector::Start => std::iter::once(&ShapeExprLabel::Start),
34        }
35    }
36}