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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use crate::CompactIri;
use iref::Iri;
use locspan_derive::StrippedPartialEq;
use std::fmt;
use std::hash::Hash;
#[derive(Clone, StrippedPartialEq, PartialOrd, Ord, Debug)]
pub struct Index(#[locspan(stripped)] String);
impl Index {
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_str(&self) -> &str {
&self.0
}
pub fn into_string(self) -> String {
self.0
}
}
impl PartialEq for Index {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl fmt::Display for Index {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl Eq for Index {}
impl Hash for Index {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.as_str().hash(state)
}
}
impl From<String> for Index {
fn from(s: String) -> Self {
Self(s)
}
}
#[derive(Clone, Copy)]
pub struct IndexRef<'a>(&'a str);
impl<'a> IndexRef<'a> {
pub fn to_owned(self) -> Index {
Index(self.0.to_owned())
}
pub fn as_str(&self) -> &'a str {
self.0
}
}
impl<'a> From<&'a Index> for IndexRef<'a> {
fn from(i: &'a Index) -> Self {
Self(&i.0)
}
}