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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::{CompactIri, ExpandableRef};
use iref::Iri;
use locspan_derive::StrippedPartialEq;
use rdf_types::BlankId;

#[derive(Clone, PartialEq, StrippedPartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct Vocab(#[locspan(stripped)] String);

impl Vocab {
	pub fn as_iri(&self) -> Option<Iri> {
		Iri::new(&self.0).ok()
	}

	pub fn as_compact_iri(&self) -> Option<&CompactIri> {
		CompactIri::new(&self.0).ok()
	}

	pub fn as_blank_id(&self) -> Option<&BlankId> {
		BlankId::new(&self.0).ok()
	}

	pub fn as_str(&self) -> &str {
		&self.0
	}

	pub fn into_string(self) -> String {
		self.0
	}
}

impl From<String> for Vocab {
	fn from(s: String) -> Self {
		Self(s)
	}
}

#[derive(Clone, Copy)]
pub struct VocabRef<'a>(&'a str);

impl<'a> VocabRef<'a> {
	pub fn as_str(&self) -> &'a str {
		self.0
	}
}

impl<'a> From<&'a Vocab> for VocabRef<'a> {
	fn from(v: &'a Vocab) -> Self {
		Self(v.as_str())
	}
}

impl<'a> From<VocabRef<'a>> for ExpandableRef<'a> {
	fn from(v: VocabRef<'a>) -> Self {
		ExpandableRef::String(v.0)
	}
}