Skip to main content

rdf_syntax/interpretation/impl/
unit.rs

1use std::borrow::Cow;
2
3use iref::Iri;
4use rdf_types::StaticDomain;
5
6use crate::{
7	CowLiteral, GroundInterpretationMut, GroundTerm, LiteralRef, Term,
8	interpretation::{GroundInterpretation, ReverseGroundInterpretation},
9};
10
11impl GroundInterpretation for StaticDomain<Term> {
12	fn iri(&self, iri: &Iri) -> Option<Term> {
13		Some(Term::iri(iri.to_owned()))
14	}
15
16	fn literal<'a>(&self, literal: impl Into<LiteralRef<'a>>) -> Option<Term> {
17		Some(Term::literal(literal.into().to_owned()))
18	}
19}
20
21impl GroundInterpretationMut for StaticDomain<Term> {
22	fn insert_iri<'a>(&mut self, iri: impl Into<Cow<'a, Iri>>) -> Self::Resource {
23		Term::iri(iri.into().into_owned())
24	}
25
26	fn insert_literal<'a>(&mut self, literal: impl Into<CowLiteral<'a>>) -> Self::Resource {
27		Term::literal(literal.into().into_owned())
28	}
29}
30
31impl ReverseGroundInterpretation for StaticDomain<Term> {
32	type Iris<'a> = std::option::IntoIter<&'a Iri>;
33	type Literals<'a> = std::option::IntoIter<LiteralRef<'a>>;
34
35	fn iris_of<'a>(&'a self, resource: &'a Self::Resource) -> Self::Iris<'a> {
36		match resource {
37			Term::Ground(GroundTerm::Iri(iri)) => Some(iri.as_iri()).into_iter(),
38			_ => None.into_iter(),
39		}
40	}
41
42	fn literals_of<'a>(&'a self, resource: &'a Self::Resource) -> Self::Literals<'a> {
43		match resource {
44			Term::Ground(GroundTerm::Literal(l)) => Some(l.as_ref()).into_iter(),
45			_ => None.into_iter(),
46		}
47	}
48}