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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use iref::IriBuf;
use ordered_float::NotNan;
use std::fmt;
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
pub enum Term {
Blank(usize),
Iri(IriBuf),
Value(Literal),
}
impl Term {
pub fn as_str(&self) -> Option<&str> {
match self {
Term::Iri(iri) => Some(iri.as_str()),
Term::Value(lit) => lit.as_str(),
_ => None,
}
}
}
impl fmt::Display for Term {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Term::Blank(id) => write!(f, "_:{}", id),
Term::Iri(iri) => write!(f, "<{}>", iri),
Term::Value(lit) => lit.fmt(f),
}
}
}
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
pub enum Literal {
String(String, Option<Tag>),
Int(i64),
Float(NotNan<f64>),
Bool(bool),
}
impl fmt::Display for Literal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Literal::String(str, Some(tag)) => write!(f, "\"{}\"{}", str, tag),
Literal::String(str, None) => write!(f, "\"{}\"", str),
Literal::Int(i) => i.fmt(f),
Literal::Float(d) => d.fmt(f),
Literal::Bool(true) => write!(f, "true"),
Literal::Bool(false) => write!(f, "false"),
}
}
}
impl Literal {
pub fn as_str(&self) -> Option<&str> {
match self {
Literal::String(str, _) => Some(str.as_str()),
_ => None,
}
}
}
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
pub enum Tag {
Lang(String),
Iri(IriBuf),
}
impl fmt::Display for Tag {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Tag::Lang(lang) => write!(f, "@{}", lang),
Tag::Iri(iri) => write!(f, "^^<{}>", iri),
}
}
}