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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
use iref::{IriRef, IriRefBuf};
use std::fmt;
mod blankid;
mod literal;
mod term;
#[cfg(feature = "loc")]
pub mod loc;
pub use blankid::*;
pub use literal::*;
pub use term::*;
pub struct Triple<S = Subject, P = IriRefBuf, O = Object>(pub S, pub P, pub O);
impl<S, P, O> Triple<S, P, O> {
pub fn new(subject: S, predicate: P, object: O) -> Self {
Self(subject, predicate, object)
}
pub fn subject(&self) -> &S {
&self.0
}
pub fn into_subject(self) -> S {
self.0
}
pub fn predicate(&self) -> &P {
&self.1
}
pub fn into_predicate(self) -> P {
self.1
}
pub fn object(&self) -> &O {
&self.2
}
pub fn into_object(self) -> O {
self.2
}
pub fn into_parts(self) -> (S, P, O) {
(self.0, self.1, self.2)
}
}
impl<S: fmt::Display, P: fmt::Display, O: fmt::Display> fmt::Display for Triple<S, P, O> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} {} {}", self.0, self.1, self.2)
}
}
pub type TripleRef<'a> = Triple<SubjectRef<'a>, IriRef<'a>, ObjectRef<'a>>;
pub struct Quad<S = Subject, P = IriRefBuf, O = Object, G = GraphLabel>(
pub S,
pub P,
pub O,
pub Option<G>,
);
impl<S, P, O, G> Quad<S, P, O, G> {
pub fn new(subject: S, predicate: P, object: O, graph: Option<G>) -> Self {
Self(subject, predicate, object, graph)
}
pub fn subject(&self) -> &S {
&self.0
}
pub fn into_subject(self) -> S {
self.0
}
pub fn predicate(&self) -> &P {
&self.1
}
pub fn into_predicate(self) -> P {
self.1
}
pub fn object(&self) -> &O {
&self.2
}
pub fn into_object(self) -> O {
self.2
}
pub fn graph(&self) -> Option<&G> {
self.3.as_ref()
}
pub fn into_graph(self) -> Option<G> {
self.3
}
pub fn into_parts(self) -> (S, P, O, Option<G>) {
(self.0, self.1, self.2, self.3)
}
}
impl<S: fmt::Display, P: fmt::Display, O: fmt::Display, G: fmt::Display> fmt::Display
for Quad<S, P, O, G>
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.graph() {
Some(graph) => write!(f, "{} {} {} {}", self.0, self.1, self.2, graph),
None => write!(f, "{} {} {}", self.0, self.1, self.2),
}
}
}
pub type QuadRef<'a> = Quad<SubjectRef<'a>, IriRef<'a>, ObjectRef<'a>, GraphLabelRef<'a>>;