Enum rdf_types::Term

source ·
pub enum Term<I = IriBuf, B = BlankIdBuf, L = Literal<StringLiteral, I>> {
    Blank(B),
    Iri(I),
    Literal(L),
}
Expand description

gRDF term.

Either a blank node identifier, IRI or literal value.

Hash implementation

It is guaranteed that the Hash implementation of Term is transparent, meaning that the hash of Term::Blank(id) the same as id, the hash of Term::Iri(iri) is the same as iri and the hash of Term::Literal(l) is the same as l.

Variants§

§

Blank(B)

Blank node identifier.

§

Iri(I)

IRI.

§

Literal(L)

Literal value.

Implementations§

Examples found in repository?
src/term.rs (line 126)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
	pub fn as_object_ref(&self) -> TermRef {
		self.as_term_ref()
	}
}

impl<S, L> Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>> {
	#[allow(clippy::type_complexity)]
	pub fn inserted_into<V: VocabularyMut>(
		&self,
		vocabulary: &mut V,
	) -> Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>
	where
		S: Clone,
		L: Clone,
	{
		match self {
			Self::Blank(b) => Term::Blank(vocabulary.insert_blank_id(b.as_blank_id_ref())),
			Self::Iri(i) => Term::Iri(vocabulary.insert(i.as_iri())),
			Self::Literal(l) => Term::Literal(l.inserted_into(vocabulary)),
		}
	}

	#[allow(clippy::type_complexity)]
	pub fn insert_into<V: VocabularyMut>(
		self,
		vocabulary: &mut V,
	) -> Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>> {
		match self {
			Self::Blank(b) => Term::Blank(vocabulary.insert_blank_id(b.as_blank_id_ref())),
			Self::Iri(i) => Term::Iri(vocabulary.insert(i.as_iri())),
			Self::Literal(l) => Term::Literal(l.insert_into(vocabulary)),
		}
	}
}

impl<I1: PartialEq<I2>, B1: PartialEq<B2>, L1: PartialEq<L2>, I2, B2, L2>
	PartialEq<Term<I2, B2, L2>> for Term<I1, B1, L1>
{
	fn eq(&self, other: &Term<I2, B2, L2>) -> bool {
		match (self, other) {
			(Self::Blank(a), Term::Blank(b)) => a == b,
			(Self::Iri(a), Term::Iri(b)) => a == b,
			(Self::Literal(a), Term::Literal(b)) => a == b,
			_ => false,
		}
	}
}

impl<I1: PartialOrd<I2>, B1: PartialOrd<B2>, L1: PartialOrd<L2>, I2, B2, L2>
	PartialOrd<Term<I2, B2, L2>> for Term<I1, B1, L1>
{
	fn partial_cmp(&self, other: &Term<I2, B2, L2>) -> Option<Ordering> {
		match (self, other) {
			(Self::Blank(a), Term::Blank(b)) => a.partial_cmp(b),
			(Self::Blank(_), _) => Some(Ordering::Less),
			(Self::Iri(a), Term::Iri(b)) => a.partial_cmp(b),
			(Self::Iri(_), Term::Blank(_)) => Some(Ordering::Greater),
			(Self::Iri(_), _) => Some(Ordering::Less),
			(Self::Literal(a), Term::Literal(b)) => a.partial_cmp(b),
			_ => Some(Ordering::Greater),
		}
	}
}

impl<I: fmt::Display, B: fmt::Display, L: fmt::Display> fmt::Display for Term<I, B, L> {
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		match self {
			Self::Blank(id) => id.fmt(f),
			Self::Iri(iri) => iri.fmt(f),
			Self::Literal(lit) => lit.fmt(f),
		}
	}
}

impl<I: fmt::Display, B: fmt::Display, L: fmt::Display> RdfDisplay for Term<I, B, L> {
	fn rdf_fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		match self {
			Self::Blank(id) => id.fmt(f),
			Self::Iri(iri) => write!(f, "<{}>", iri),
			Self::Literal(lit) => lit.fmt(f),
		}
	}
}

#[cfg(feature = "contextual")]
impl<I, B, L: DisplayWithContext<V>, V: crate::Vocabulary<Iri = I, BlankId = B>>
	DisplayWithContext<V> for Term<I, B, L>
{
	fn fmt_with(&self, vocabulary: &V, f: &mut fmt::Formatter) -> fmt::Result {
		use fmt::Display;
		match self {
			Self::Blank(id) => vocabulary.blank_id(id).unwrap().fmt(f),
			Self::Iri(iri) => vocabulary.iri(iri).unwrap().fmt(f),
			Self::Literal(lit) => lit.fmt_with(vocabulary, f),
		}
	}
}

#[cfg(feature = "contextual")]
impl<I, B, L: crate::RdfDisplayWithContext<V>, V: crate::Vocabulary<Iri = I, BlankId = B>>
	crate::RdfDisplayWithContext<V> for Term<I, B, L>
{
	fn rdf_fmt_with(&self, vocabulary: &V, f: &mut fmt::Formatter) -> fmt::Result {
		use fmt::Display;
		match self {
			Self::Blank(id) => vocabulary.blank_id(id).unwrap().fmt(f),
			Self::Iri(iri) => write!(f, "<{}>", vocabulary.iri(iri).unwrap()),
			Self::Literal(lit) => lit.rdf_fmt_with(vocabulary, f),
		}
	}
}

#[cfg(feature = "contextual")]
impl<I, B, L: AsRef<str>, V: crate::Vocabulary<Iri = I, BlankId = B>> AsRefWithContext<str, V>
	for Term<I, B, L>
{
	fn as_ref_with<'a>(&'a self, vocabulary: &'a V) -> &'a str {
		match self {
			Self::Blank(b) => vocabulary.blank_id(b).unwrap().as_str(),
			Self::Iri(i) => vocabulary.iri(i).unwrap().into_str(),
			Self::Literal(l) => l.as_ref(),
		}
	}
}

impl<I, B, L> AsTerm for Term<I, B, L> {
	type Iri = I;
	type BlankId = B;
	type Literal = L;

	fn as_term(&self) -> Term<&I, &B, &L> {
		match self {
			Self::Iri(iri) => Term::Iri(iri),
			Self::Blank(id) => Term::Blank(id),
			Self::Literal(lit) => Term::Literal(lit),
		}
	}
}

impl<I, B, L> IntoTerm for Term<I, B, L> {
	type Iri = I;
	type BlankId = B;
	type Literal = L;

	fn into_term(self) -> Term<I, B, L> {
		match self {
			Self::Iri(iri) => Term::Iri(iri),
			Self::Blank(id) => Term::Blank(id),
			Self::Literal(lit) => Term::Literal(lit),
		}
	}
}

/// gRDF term reference.
pub type TermRef<'a> = Term<Iri<'a>, &'a BlankId, &'a Literal>;

impl<'a> TermRef<'a> {
	pub fn into_owned(self) -> Term {
		match self {
			Self::Iri(iri) => Term::Iri(iri.to_owned()),
			Self::Blank(b) => Term::Blank(b.to_owned()),
			Self::Literal(l) => Term::Literal(l.clone()),
		}
	}
}

impl<'a> From<&'a Term> for TermRef<'a> {
	fn from(t: &'a Term) -> Self {
		t.as_term_ref()
	}
More examples
Hide additional examples
src/lib.rs (line 88)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
	pub fn as_grdf(&self) -> GrdfTripleRef {
		Triple(
			self.0.as_term_ref(),
			TermRef::Iri(self.1.as_iri()),
			self.2.as_term_ref(),
		)
	}
}

impl<S, P, O> Triple<S, P, O> {
	/// Creates a new triple.
	pub fn new(subject: S, predicate: P, object: O) -> Self {
		Self(subject, predicate, object)
	}

	/// Returns a reference to the subject of the triple,
	/// the first component.
	pub fn subject(&self) -> &S {
		&self.0
	}

	/// Returns a mutable reference to the subject of the triple,
	/// the first component.
	pub fn subject_mut(&mut self) -> &mut S {
		&mut self.0
	}

	/// Turns the triple into its subject,
	/// the first component.
	pub fn into_subject(self) -> S {
		self.0
	}

	/// Returns a reference to the predicate of the triple,
	/// the second component.
	pub fn predicate(&self) -> &P {
		&self.1
	}

	/// Returns a mutable reference to the predicate of the triple,
	/// the second component.
	pub fn predicate_mut(&mut self) -> &mut P {
		&mut self.1
	}

	/// Turns the triple into its predicate,
	/// the second component.
	pub fn into_predicate(self) -> P {
		self.1
	}

	/// Returns a reference to the object of the triple,
	/// the third component.
	pub fn object(&self) -> &O {
		&self.2
	}

	/// Returns a mutable reference to the object of the triple,
	/// the third component.
	pub fn object_mut(&mut self) -> &mut O {
		&mut self.2
	}

	/// Turns the triple into its object,
	/// the third component.
	pub fn into_object(self) -> O {
		self.2
	}

	/// Turns the triple into a tuple
	pub fn into_parts(self) -> (S, P, O) {
		(self.0, self.1, self.2)
	}

	/// Maps the subject with the given function.
	pub fn map_subject<U>(self, f: impl FnOnce(S) -> U) -> Triple<U, P, O> {
		Triple(f(self.0), self.1, self.2)
	}

	/// Maps the subject with the given function.
	pub fn map_predicate<U>(self, f: impl FnOnce(P) -> U) -> Triple<S, U, O> {
		Triple(self.0, f(self.1), self.2)
	}

	/// Maps the subject with the given function.
	pub fn map_object<U>(self, f: impl FnOnce(O) -> U) -> Triple<S, P, U> {
		Triple(self.0, self.1, f(self.2))
	}
}

impl<S, L> Triple<Subject, IriBuf, Object<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>> {
	#[allow(clippy::type_complexity)]
	pub fn inserted_into<V: VocabularyMut>(
		&self,
		vocabulary: &mut V,
	) -> Triple<
		Subject<V::Iri, V::BlankId>,
		V::Iri,
		Object<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	>
	where
		S: Clone,
		L: Clone,
	{
		Triple(
			self.0.inserted_into(vocabulary),
			vocabulary.insert(self.1.as_iri()),
			self.2.inserted_into(vocabulary),
		)
	}

	#[allow(clippy::type_complexity)]
	pub fn insert_into<V: VocabularyMut>(
		self,
		vocabulary: &mut V,
	) -> Triple<
		Subject<V::Iri, V::BlankId>,
		V::Iri,
		Object<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	> {
		Triple(
			self.0.insert_into(vocabulary),
			vocabulary.insert(self.1.as_iri()),
			self.2.insert_into(vocabulary),
		)
	}
}

impl<S, L>
	Quad<
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
	>
{
	#[allow(clippy::type_complexity)]
	pub fn inserted_into<V: VocabularyMut>(
		&self,
		vocabulary: &mut V,
	) -> Triple<
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	>
	where
		S: Clone,
		L: Clone,
	{
		Triple(
			self.0.inserted_into(vocabulary),
			self.1.inserted_into(vocabulary),
			self.2.inserted_into(vocabulary),
		)
	}

	#[allow(clippy::type_complexity)]
	pub fn insert_into<V: VocabularyMut>(
		self,
		vocabulary: &mut V,
	) -> Triple<
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	> {
		Triple(
			self.0.insert_into(vocabulary),
			self.1.insert_into(vocabulary),
			self.2.insert_into(vocabulary),
		)
	}
}

impl<S: RdfDisplay, P: RdfDisplay, O: RdfDisplay> fmt::Display for Triple<S, P, O> {
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		write!(
			f,
			"{} {} {}",
			self.0.rdf_display(),
			self.1.rdf_display(),
			self.2.rdf_display()
		)
	}
}

impl<S: RdfDisplay, P: RdfDisplay, O: RdfDisplay> RdfDisplay for Triple<S, P, O> {
	fn rdf_fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		write!(
			f,
			"{} {} {}",
			self.0.rdf_display(),
			self.1.rdf_display(),
			self.2.rdf_display()
		)
	}
}

#[cfg(feature = "contextual")]
impl<S: RdfDisplayWithContext<V>, P: RdfDisplayWithContext<V>, O: RdfDisplayWithContext<V>, V>
	DisplayWithContext<V> for Triple<S, P, O>
{
	fn fmt_with(&self, vocabulary: &V, f: &mut fmt::Formatter) -> fmt::Result {
		write!(
			f,
			"{} {} {}",
			self.0.with(vocabulary).rdf_display(),
			self.1.with(vocabulary).rdf_display(),
			self.2.with(vocabulary).rdf_display()
		)
	}
}

#[cfg(feature = "contextual")]
impl<S: RdfDisplayWithContext<V>, P: RdfDisplayWithContext<V>, O: RdfDisplayWithContext<V>, V>
	RdfDisplayWithContext<V> for Triple<S, P, O>
{
	fn rdf_fmt_with(&self, vocabulary: &V, f: &mut fmt::Formatter) -> fmt::Result {
		write!(
			f,
			"{} {} {}",
			self.0.with(vocabulary).rdf_display(),
			self.1.with(vocabulary).rdf_display(),
			self.2.with(vocabulary).rdf_display()
		)
	}
}

/// RDF triple reference.
pub type TripleRef<'a> = Triple<SubjectRef<'a>, Iri<'a>, ObjectRef<'a>>;

/// gRDF triple.
pub type GrdfTriple = Triple<Term, Term, Term>;

/// gRDF triple reference.
pub type GrdfTripleRef<'a> = Triple<TermRef<'a>, TermRef<'a>, TermRef<'a>>;

/// RDF quad.
#[derive(Clone, Copy, Eq, Ord, Hash, Debug)]
#[cfg_attr(
	feature = "meta",
	derive(
		StrippedPartialEq,
		StrippedEq,
		StrippedPartialOrd,
		StrippedOrd,
		StrippedHash
	)
)]
pub struct Quad<S = Subject, P = IriBuf, O = Object, G = GraphLabel>(
	pub S,
	pub P,
	pub O,
	pub Option<G>,
);

impl Quad {
	pub fn into_grdf(self) -> GrdfQuad {
		Quad(
			self.0.into_term(),
			Term::Iri(self.1),
			self.2,
			self.3.map(GraphLabel::into_term),
		)
	}

	pub fn as_grdf(&self) -> GrdfQuadRef {
		Quad(
			self.0.as_term_ref(),
			TermRef::Iri(self.1.as_iri()),
			self.2.as_term_ref(),
			self.3.as_ref().map(GraphLabel::as_term_ref),
		)
	}
}

impl<S, L> Quad<Subject, IriBuf, Object<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>, GraphLabel> {
	#[allow(clippy::type_complexity)]
	pub fn inserted_into<V: VocabularyMut>(
		&self,
		vocabulary: &mut V,
	) -> Quad<
		Subject<V::Iri, V::BlankId>,
		V::Iri,
		Object<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		GraphLabel<V::Iri, V::BlankId>,
	>
	where
		S: Clone,
		L: Clone,
	{
		Quad(
			self.0.inserted_into(vocabulary),
			vocabulary.insert(self.1.as_iri()),
			self.2.inserted_into(vocabulary),
			self.3.as_ref().map(|g| g.inserted_into(vocabulary)),
		)
	}

	#[allow(clippy::type_complexity)]
	pub fn insert_into<V: VocabularyMut>(
		self,
		vocabulary: &mut V,
	) -> Quad<
		Subject<V::Iri, V::BlankId>,
		V::Iri,
		Object<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		GraphLabel<V::Iri, V::BlankId>,
	> {
		Quad(
			self.0.insert_into(vocabulary),
			vocabulary.insert(self.1.as_iri()),
			self.2.insert_into(vocabulary),
			self.3.map(|g| g.insert_into(vocabulary)),
		)
	}
}

impl<S, L>
	Quad<
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
	>
{
	#[allow(clippy::type_complexity)]
	pub fn inserted_into<V: VocabularyMut>(
		&self,
		vocabulary: &mut V,
	) -> Quad<
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	>
	where
		S: Clone,
		L: Clone,
	{
		Quad(
			self.0.inserted_into(vocabulary),
			self.1.inserted_into(vocabulary),
			self.2.inserted_into(vocabulary),
			self.3.as_ref().map(|g| g.inserted_into(vocabulary)),
		)
	}

	#[allow(clippy::type_complexity)]
	pub fn insert_into<V: VocabularyMut>(
		self,
		vocabulary: &mut V,
	) -> Quad<
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	> {
		Quad(
			self.0.insert_into(vocabulary),
			self.1.insert_into(vocabulary),
			self.2.insert_into(vocabulary),
			self.3.map(|g| g.insert_into(vocabulary)),
		)
	}
}

impl<S, P, O, G> Quad<S, P, O, G> {
	/// Creates a new quad.
	pub fn new(subject: S, predicate: P, object: O, graph: Option<G>) -> Self {
		Self(subject, predicate, object, graph)
	}

	/// Returns a reference to the subject of the quad,
	/// the first component.
	pub fn subject(&self) -> &S {
		&self.0
	}

	/// Returns a mutable reference to the subject of the quad,
	/// the first component.
	pub fn subject_mut(&mut self) -> &mut S {
		&mut self.0
	}

	/// Turns the quad into its subject,
	/// the first component.
	pub fn into_subject(self) -> S {
		self.0
	}

	/// Returns a reference to the predicate of the quad,
	/// the second component.
	pub fn predicate(&self) -> &P {
		&self.1
	}

	/// Returns a mutable reference to the predicate of the quad,
	/// the second component.
	pub fn predicate_mut(&mut self) -> &mut P {
		&mut self.1
	}

	/// Turns the quad into its predicate,
	/// the second component.
	pub fn into_predicate(self) -> P {
		self.1
	}

	/// Returns a reference to the object of the quad,
	/// the third component.
	pub fn object(&self) -> &O {
		&self.2
	}

	/// Returns a mutable reference to the object of the quad,
	/// the third component.
	pub fn object_mut(&mut self) -> &mut O {
		&mut self.2
	}

	/// Turns the quad into its object,
	/// the third component.
	pub fn into_object(self) -> O {
		self.2
	}

	/// Returns a reference to the graph of the quad,
	/// the fourth component.
	pub fn graph(&self) -> Option<&G> {
		self.3.as_ref()
	}

	/// Returns a mutable reference to the graph of the quad,
	/// the fourth component.
	pub fn graph_mut(&mut self) -> Option<&mut G> {
		self.3.as_mut()
	}

	/// Turns the quad into its graph,
	/// the fourth component.
	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)
	}

	/// Maps the subject with the given function.
	pub fn map_subject<U>(self, f: impl FnOnce(S) -> U) -> Quad<U, P, O, G> {
		Quad(f(self.0), self.1, self.2, self.3)
	}

	/// Maps the subject with the given function.
	pub fn map_predicate<U>(self, f: impl FnOnce(P) -> U) -> Quad<S, U, O, G> {
		Quad(self.0, f(self.1), self.2, self.3)
	}

	/// Maps the subject with the given function.
	pub fn map_object<U>(self, f: impl FnOnce(O) -> U) -> Quad<S, P, U, G> {
		Quad(self.0, self.1, f(self.2), self.3)
	}

	/// Maps the graph with the given function.
	pub fn map_graph<U>(self, f: impl FnOnce(Option<G>) -> Option<U>) -> Quad<S, P, O, U> {
		Quad(self.0, self.1, self.2, f(self.3))
	}
}

impl<
		S1: PartialEq<S2>,
		P1: PartialEq<P2>,
		O1: PartialEq<O2>,
		G1: PartialEq<G2>,
		S2,
		P2,
		O2,
		G2,
	> PartialEq<Quad<S2, P2, O2, G2>> for Quad<S1, P1, O1, G1>
{
	fn eq(&self, other: &Quad<S2, P2, O2, G2>) -> bool {
		self.0 == other.0
			&& self.1 == other.1
			&& self.2 == other.2
			&& match (&self.3, &other.3) {
				(Some(a), Some(b)) => a == b,
				(None, None) => true,
				_ => false,
			}
	}
}

impl<
		S1: PartialOrd<S2>,
		P1: PartialOrd<P2>,
		O1: PartialOrd<O2>,
		G1: PartialOrd<G2>,
		S2,
		P2,
		O2,
		G2,
	> PartialOrd<Quad<S2, P2, O2, G2>> for Quad<S1, P1, O1, G1>
{
	fn partial_cmp(&self, other: &Quad<S2, P2, O2, G2>) -> Option<Ordering> {
		match self.0.partial_cmp(&other.0) {
			Some(Ordering::Equal) => match self.1.partial_cmp(&other.1) {
				Some(Ordering::Equal) => match self.2.partial_cmp(&other.2) {
					Some(Ordering::Equal) => match (&self.3, &other.3) {
						(Some(a), Some(b)) => a.partial_cmp(b),
						(Some(_), None) => Some(Ordering::Greater),
						(None, Some(_)) => Some(Ordering::Less),
						(None, None) => Some(Ordering::Equal),
					},
					cmp => cmp,
				},
				cmp => cmp,
			},
			cmp => cmp,
		}
	}
}

impl<S: RdfDisplay, P: RdfDisplay, O: RdfDisplay, G: RdfDisplay> 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.rdf_display(),
				self.1.rdf_display(),
				self.2.rdf_display(),
				graph.rdf_display()
			),
			None => write!(
				f,
				"{} {} {}",
				self.0.rdf_display(),
				self.1.rdf_display(),
				self.2.rdf_display()
			),
		}
	}
}

impl<S: RdfDisplay, P: RdfDisplay, O: RdfDisplay, G: RdfDisplay> RdfDisplay for Quad<S, P, O, G> {
	fn rdf_fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		match self.graph() {
			Some(graph) => write!(
				f,
				"{} {} {} {}",
				self.0.rdf_display(),
				self.1.rdf_display(),
				self.2.rdf_display(),
				graph.rdf_display()
			),
			None => write!(
				f,
				"{} {} {}",
				self.0.rdf_display(),
				self.1.rdf_display(),
				self.2.rdf_display()
			),
		}
	}
}

#[cfg(feature = "contextual")]
impl<
		S: RdfDisplayWithContext<V>,
		P: RdfDisplayWithContext<V>,
		O: RdfDisplayWithContext<V>,
		G: RdfDisplayWithContext<V>,
		V,
	> DisplayWithContext<V> for Quad<S, P, O, G>
{
	fn fmt_with(&self, vocabulary: &V, f: &mut fmt::Formatter) -> fmt::Result {
		match self.graph() {
			Some(graph) => write!(
				f,
				"{} {} {} {}",
				self.0.with(vocabulary).rdf_display(),
				self.1.with(vocabulary).rdf_display(),
				self.2.with(vocabulary).rdf_display(),
				graph.with(vocabulary).rdf_display()
			),
			None => write!(
				f,
				"{} {} {}",
				self.0.with(vocabulary).rdf_display(),
				self.1.with(vocabulary).rdf_display(),
				self.2.with(vocabulary).rdf_display()
			),
		}
	}
}

#[cfg(feature = "contextual")]
impl<
		S: RdfDisplayWithContext<V>,
		P: RdfDisplayWithContext<V>,
		O: RdfDisplayWithContext<V>,
		G: RdfDisplayWithContext<V>,
		V,
	> RdfDisplayWithContext<V> for Quad<S, P, O, G>
{
	fn rdf_fmt_with(&self, vocabulary: &V, f: &mut fmt::Formatter) -> fmt::Result {
		match self.graph() {
			Some(graph) => write!(
				f,
				"{} {} {} {}",
				self.0.with(vocabulary).rdf_display(),
				self.1.with(vocabulary).rdf_display(),
				self.2.with(vocabulary).rdf_display(),
				graph.with(vocabulary).rdf_display()
			),
			None => write!(
				f,
				"{} {} {}",
				self.0.with(vocabulary).rdf_display(),
				self.1.with(vocabulary).rdf_display(),
				self.2.with(vocabulary).rdf_display()
			),
		}
	}
}

impl Quad {
	#[inline(always)]
	pub fn as_quad_ref(&self) -> QuadRef {
		Quad(
			self.0.as_subject_ref(),
			self.1.as_iri(),
			self.2.as_object_ref(),
			self.3.as_ref().map(GraphLabel::as_graph_label_ref),
		)
	}
}

impl<'a> From<QuadRef<'a>> for Quad {
	#[inline(always)]
	fn from(q: QuadRef<'a>) -> Self {
		q.into_owned()
	}
}

impl GrdfQuad {
	#[inline(always)]
	pub fn as_grdf_quad_ref(&self) -> GrdfQuadRef {
		Quad(
			self.0.as_term_ref(),
			self.1.as_term_ref(),
			self.2.as_term_ref(),
			self.3.as_ref().map(Term::as_term_ref),
		)
	}
}

impl<'a> From<GrdfQuadRef<'a>> for GrdfQuad {
	#[inline(always)]
	fn from(q: GrdfQuadRef<'a>) -> Self {
		q.into_owned()
	}
}

/// RDF quad reference.
pub type QuadRef<'a> = Quad<SubjectRef<'a>, Iri<'a>, ObjectRef<'a>, GraphLabelRef<'a>>;

impl<'a> QuadRef<'a> {
	#[inline(always)]
	pub fn into_owned(self) -> Quad {
		Quad(
			self.0.into_owned(),
			self.1.to_owned(),
			self.2.into_owned(),
			self.3.map(GraphLabelRef::into_owned),
		)
	}
}

impl<'a> From<&'a Quad> for QuadRef<'a> {
	#[inline(always)]
	fn from(q: &'a Quad) -> Self {
		q.as_quad_ref()
	}
}

impl<'a> From<Quad<&'a Subject, &'a IriBuf, &'a Object, &'a GraphLabel>> for QuadRef<'a> {
	#[inline(always)]
	fn from(Quad(s, p, o, g): Quad<&'a Subject, &'a IriBuf, &'a Object, &'a GraphLabel>) -> Self {
		Quad(
			s.as_subject_ref(),
			p.as_iri(),
			o.as_object_ref(),
			g.map(GraphLabel::as_graph_label_ref),
		)
	}
}

/// gRDF quad.
pub type GrdfQuad = Quad<Term, Term, Term, Term>;

/// gRDF quad reference.
pub type GrdfQuadRef<'a> = Quad<TermRef<'a>, TermRef<'a>, TermRef<'a>, TermRef<'a>>;

impl<'a> GrdfQuadRef<'a> {
	#[inline(always)]
	pub fn into_owned(self) -> GrdfQuad {
		Quad(
			self.0.into_owned(),
			self.1.into_owned(),
			self.2.into_owned(),
			self.3.map(Term::into_owned),
		)
	}
}

impl<'a> From<&'a GrdfQuad> for GrdfQuadRef<'a> {
	#[inline(always)]
	fn from(q: &'a GrdfQuad) -> Self {
		q.as_grdf_quad_ref()
	}
}

impl<'a> From<Quad<&'a Term, &'a Term, &'a Term, &'a Term>> for GrdfQuadRef<'a> {
	#[inline(always)]
	fn from(Quad(s, p, o, g): Quad<&'a Term, &'a Term, &'a Term, &'a Term>) -> Self {
		Quad(
			s.as_term_ref(),
			p.as_term_ref(),
			o.as_term_ref(),
			g.map(Term::as_term_ref),
		)
	}
Examples found in repository?
src/lib.rs (line 715)
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
	pub fn as_quad_ref(&self) -> QuadRef {
		Quad(
			self.0.as_subject_ref(),
			self.1.as_iri(),
			self.2.as_object_ref(),
			self.3.as_ref().map(GraphLabel::as_graph_label_ref),
		)
	}
}

impl<'a> From<QuadRef<'a>> for Quad {
	#[inline(always)]
	fn from(q: QuadRef<'a>) -> Self {
		q.into_owned()
	}
}

impl GrdfQuad {
	#[inline(always)]
	pub fn as_grdf_quad_ref(&self) -> GrdfQuadRef {
		Quad(
			self.0.as_term_ref(),
			self.1.as_term_ref(),
			self.2.as_term_ref(),
			self.3.as_ref().map(Term::as_term_ref),
		)
	}
}

impl<'a> From<GrdfQuadRef<'a>> for GrdfQuad {
	#[inline(always)]
	fn from(q: GrdfQuadRef<'a>) -> Self {
		q.into_owned()
	}
}

/// RDF quad reference.
pub type QuadRef<'a> = Quad<SubjectRef<'a>, Iri<'a>, ObjectRef<'a>, GraphLabelRef<'a>>;

impl<'a> QuadRef<'a> {
	#[inline(always)]
	pub fn into_owned(self) -> Quad {
		Quad(
			self.0.into_owned(),
			self.1.to_owned(),
			self.2.into_owned(),
			self.3.map(GraphLabelRef::into_owned),
		)
	}
}

impl<'a> From<&'a Quad> for QuadRef<'a> {
	#[inline(always)]
	fn from(q: &'a Quad) -> Self {
		q.as_quad_ref()
	}
}

impl<'a> From<Quad<&'a Subject, &'a IriBuf, &'a Object, &'a GraphLabel>> for QuadRef<'a> {
	#[inline(always)]
	fn from(Quad(s, p, o, g): Quad<&'a Subject, &'a IriBuf, &'a Object, &'a GraphLabel>) -> Self {
		Quad(
			s.as_subject_ref(),
			p.as_iri(),
			o.as_object_ref(),
			g.map(GraphLabel::as_graph_label_ref),
		)
	}
Examples found in repository?
src/lib.rs (line 191)
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
	pub fn inserted_into<V: VocabularyMut>(
		&self,
		vocabulary: &mut V,
	) -> Triple<
		Subject<V::Iri, V::BlankId>,
		V::Iri,
		Object<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	>
	where
		S: Clone,
		L: Clone,
	{
		Triple(
			self.0.inserted_into(vocabulary),
			vocabulary.insert(self.1.as_iri()),
			self.2.inserted_into(vocabulary),
		)
	}

	#[allow(clippy::type_complexity)]
	pub fn insert_into<V: VocabularyMut>(
		self,
		vocabulary: &mut V,
	) -> Triple<
		Subject<V::Iri, V::BlankId>,
		V::Iri,
		Object<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	> {
		Triple(
			self.0.insert_into(vocabulary),
			vocabulary.insert(self.1.as_iri()),
			self.2.insert_into(vocabulary),
		)
	}
}

impl<S, L>
	Quad<
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
	>
{
	#[allow(clippy::type_complexity)]
	pub fn inserted_into<V: VocabularyMut>(
		&self,
		vocabulary: &mut V,
	) -> Triple<
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	>
	where
		S: Clone,
		L: Clone,
	{
		Triple(
			self.0.inserted_into(vocabulary),
			self.1.inserted_into(vocabulary),
			self.2.inserted_into(vocabulary),
		)
	}

	#[allow(clippy::type_complexity)]
	pub fn insert_into<V: VocabularyMut>(
		self,
		vocabulary: &mut V,
	) -> Triple<
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	> {
		Triple(
			self.0.insert_into(vocabulary),
			self.1.insert_into(vocabulary),
			self.2.insert_into(vocabulary),
		)
	}
}

impl<S: RdfDisplay, P: RdfDisplay, O: RdfDisplay> fmt::Display for Triple<S, P, O> {
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		write!(
			f,
			"{} {} {}",
			self.0.rdf_display(),
			self.1.rdf_display(),
			self.2.rdf_display()
		)
	}
}

impl<S: RdfDisplay, P: RdfDisplay, O: RdfDisplay> RdfDisplay for Triple<S, P, O> {
	fn rdf_fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		write!(
			f,
			"{} {} {}",
			self.0.rdf_display(),
			self.1.rdf_display(),
			self.2.rdf_display()
		)
	}
}

#[cfg(feature = "contextual")]
impl<S: RdfDisplayWithContext<V>, P: RdfDisplayWithContext<V>, O: RdfDisplayWithContext<V>, V>
	DisplayWithContext<V> for Triple<S, P, O>
{
	fn fmt_with(&self, vocabulary: &V, f: &mut fmt::Formatter) -> fmt::Result {
		write!(
			f,
			"{} {} {}",
			self.0.with(vocabulary).rdf_display(),
			self.1.with(vocabulary).rdf_display(),
			self.2.with(vocabulary).rdf_display()
		)
	}
}

#[cfg(feature = "contextual")]
impl<S: RdfDisplayWithContext<V>, P: RdfDisplayWithContext<V>, O: RdfDisplayWithContext<V>, V>
	RdfDisplayWithContext<V> for Triple<S, P, O>
{
	fn rdf_fmt_with(&self, vocabulary: &V, f: &mut fmt::Formatter) -> fmt::Result {
		write!(
			f,
			"{} {} {}",
			self.0.with(vocabulary).rdf_display(),
			self.1.with(vocabulary).rdf_display(),
			self.2.with(vocabulary).rdf_display()
		)
	}
}

/// RDF triple reference.
pub type TripleRef<'a> = Triple<SubjectRef<'a>, Iri<'a>, ObjectRef<'a>>;

/// gRDF triple.
pub type GrdfTriple = Triple<Term, Term, Term>;

/// gRDF triple reference.
pub type GrdfTripleRef<'a> = Triple<TermRef<'a>, TermRef<'a>, TermRef<'a>>;

/// RDF quad.
#[derive(Clone, Copy, Eq, Ord, Hash, Debug)]
#[cfg_attr(
	feature = "meta",
	derive(
		StrippedPartialEq,
		StrippedEq,
		StrippedPartialOrd,
		StrippedOrd,
		StrippedHash
	)
)]
pub struct Quad<S = Subject, P = IriBuf, O = Object, G = GraphLabel>(
	pub S,
	pub P,
	pub O,
	pub Option<G>,
);

impl Quad {
	pub fn into_grdf(self) -> GrdfQuad {
		Quad(
			self.0.into_term(),
			Term::Iri(self.1),
			self.2,
			self.3.map(GraphLabel::into_term),
		)
	}

	pub fn as_grdf(&self) -> GrdfQuadRef {
		Quad(
			self.0.as_term_ref(),
			TermRef::Iri(self.1.as_iri()),
			self.2.as_term_ref(),
			self.3.as_ref().map(GraphLabel::as_term_ref),
		)
	}
}

impl<S, L> Quad<Subject, IriBuf, Object<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>, GraphLabel> {
	#[allow(clippy::type_complexity)]
	pub fn inserted_into<V: VocabularyMut>(
		&self,
		vocabulary: &mut V,
	) -> Quad<
		Subject<V::Iri, V::BlankId>,
		V::Iri,
		Object<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		GraphLabel<V::Iri, V::BlankId>,
	>
	where
		S: Clone,
		L: Clone,
	{
		Quad(
			self.0.inserted_into(vocabulary),
			vocabulary.insert(self.1.as_iri()),
			self.2.inserted_into(vocabulary),
			self.3.as_ref().map(|g| g.inserted_into(vocabulary)),
		)
	}

	#[allow(clippy::type_complexity)]
	pub fn insert_into<V: VocabularyMut>(
		self,
		vocabulary: &mut V,
	) -> Quad<
		Subject<V::Iri, V::BlankId>,
		V::Iri,
		Object<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		GraphLabel<V::Iri, V::BlankId>,
	> {
		Quad(
			self.0.insert_into(vocabulary),
			vocabulary.insert(self.1.as_iri()),
			self.2.insert_into(vocabulary),
			self.3.map(|g| g.insert_into(vocabulary)),
		)
	}
}

impl<S, L>
	Quad<
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
	>
{
	#[allow(clippy::type_complexity)]
	pub fn inserted_into<V: VocabularyMut>(
		&self,
		vocabulary: &mut V,
	) -> Quad<
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	>
	where
		S: Clone,
		L: Clone,
	{
		Quad(
			self.0.inserted_into(vocabulary),
			self.1.inserted_into(vocabulary),
			self.2.inserted_into(vocabulary),
			self.3.as_ref().map(|g| g.inserted_into(vocabulary)),
		)
	}
Examples found in repository?
src/lib.rs (line 207)
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
	pub fn insert_into<V: VocabularyMut>(
		self,
		vocabulary: &mut V,
	) -> Triple<
		Subject<V::Iri, V::BlankId>,
		V::Iri,
		Object<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	> {
		Triple(
			self.0.insert_into(vocabulary),
			vocabulary.insert(self.1.as_iri()),
			self.2.insert_into(vocabulary),
		)
	}
}

impl<S, L>
	Quad<
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
	>
{
	#[allow(clippy::type_complexity)]
	pub fn inserted_into<V: VocabularyMut>(
		&self,
		vocabulary: &mut V,
	) -> Triple<
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	>
	where
		S: Clone,
		L: Clone,
	{
		Triple(
			self.0.inserted_into(vocabulary),
			self.1.inserted_into(vocabulary),
			self.2.inserted_into(vocabulary),
		)
	}

	#[allow(clippy::type_complexity)]
	pub fn insert_into<V: VocabularyMut>(
		self,
		vocabulary: &mut V,
	) -> Triple<
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	> {
		Triple(
			self.0.insert_into(vocabulary),
			self.1.insert_into(vocabulary),
			self.2.insert_into(vocabulary),
		)
	}
}

impl<S: RdfDisplay, P: RdfDisplay, O: RdfDisplay> fmt::Display for Triple<S, P, O> {
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		write!(
			f,
			"{} {} {}",
			self.0.rdf_display(),
			self.1.rdf_display(),
			self.2.rdf_display()
		)
	}
}

impl<S: RdfDisplay, P: RdfDisplay, O: RdfDisplay> RdfDisplay for Triple<S, P, O> {
	fn rdf_fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		write!(
			f,
			"{} {} {}",
			self.0.rdf_display(),
			self.1.rdf_display(),
			self.2.rdf_display()
		)
	}
}

#[cfg(feature = "contextual")]
impl<S: RdfDisplayWithContext<V>, P: RdfDisplayWithContext<V>, O: RdfDisplayWithContext<V>, V>
	DisplayWithContext<V> for Triple<S, P, O>
{
	fn fmt_with(&self, vocabulary: &V, f: &mut fmt::Formatter) -> fmt::Result {
		write!(
			f,
			"{} {} {}",
			self.0.with(vocabulary).rdf_display(),
			self.1.with(vocabulary).rdf_display(),
			self.2.with(vocabulary).rdf_display()
		)
	}
}

#[cfg(feature = "contextual")]
impl<S: RdfDisplayWithContext<V>, P: RdfDisplayWithContext<V>, O: RdfDisplayWithContext<V>, V>
	RdfDisplayWithContext<V> for Triple<S, P, O>
{
	fn rdf_fmt_with(&self, vocabulary: &V, f: &mut fmt::Formatter) -> fmt::Result {
		write!(
			f,
			"{} {} {}",
			self.0.with(vocabulary).rdf_display(),
			self.1.with(vocabulary).rdf_display(),
			self.2.with(vocabulary).rdf_display()
		)
	}
}

/// RDF triple reference.
pub type TripleRef<'a> = Triple<SubjectRef<'a>, Iri<'a>, ObjectRef<'a>>;

/// gRDF triple.
pub type GrdfTriple = Triple<Term, Term, Term>;

/// gRDF triple reference.
pub type GrdfTripleRef<'a> = Triple<TermRef<'a>, TermRef<'a>, TermRef<'a>>;

/// RDF quad.
#[derive(Clone, Copy, Eq, Ord, Hash, Debug)]
#[cfg_attr(
	feature = "meta",
	derive(
		StrippedPartialEq,
		StrippedEq,
		StrippedPartialOrd,
		StrippedOrd,
		StrippedHash
	)
)]
pub struct Quad<S = Subject, P = IriBuf, O = Object, G = GraphLabel>(
	pub S,
	pub P,
	pub O,
	pub Option<G>,
);

impl Quad {
	pub fn into_grdf(self) -> GrdfQuad {
		Quad(
			self.0.into_term(),
			Term::Iri(self.1),
			self.2,
			self.3.map(GraphLabel::into_term),
		)
	}

	pub fn as_grdf(&self) -> GrdfQuadRef {
		Quad(
			self.0.as_term_ref(),
			TermRef::Iri(self.1.as_iri()),
			self.2.as_term_ref(),
			self.3.as_ref().map(GraphLabel::as_term_ref),
		)
	}
}

impl<S, L> Quad<Subject, IriBuf, Object<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>, GraphLabel> {
	#[allow(clippy::type_complexity)]
	pub fn inserted_into<V: VocabularyMut>(
		&self,
		vocabulary: &mut V,
	) -> Quad<
		Subject<V::Iri, V::BlankId>,
		V::Iri,
		Object<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		GraphLabel<V::Iri, V::BlankId>,
	>
	where
		S: Clone,
		L: Clone,
	{
		Quad(
			self.0.inserted_into(vocabulary),
			vocabulary.insert(self.1.as_iri()),
			self.2.inserted_into(vocabulary),
			self.3.as_ref().map(|g| g.inserted_into(vocabulary)),
		)
	}

	#[allow(clippy::type_complexity)]
	pub fn insert_into<V: VocabularyMut>(
		self,
		vocabulary: &mut V,
	) -> Quad<
		Subject<V::Iri, V::BlankId>,
		V::Iri,
		Object<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		GraphLabel<V::Iri, V::BlankId>,
	> {
		Quad(
			self.0.insert_into(vocabulary),
			vocabulary.insert(self.1.as_iri()),
			self.2.insert_into(vocabulary),
			self.3.map(|g| g.insert_into(vocabulary)),
		)
	}
}

impl<S, L>
	Quad<
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
		Term<IriBuf, BlankIdBuf, Literal<S, IriBuf, L>>,
	>
{
	#[allow(clippy::type_complexity)]
	pub fn inserted_into<V: VocabularyMut>(
		&self,
		vocabulary: &mut V,
	) -> Quad<
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	>
	where
		S: Clone,
		L: Clone,
	{
		Quad(
			self.0.inserted_into(vocabulary),
			self.1.inserted_into(vocabulary),
			self.2.inserted_into(vocabulary),
			self.3.as_ref().map(|g| g.inserted_into(vocabulary)),
		)
	}

	#[allow(clippy::type_complexity)]
	pub fn insert_into<V: VocabularyMut>(
		self,
		vocabulary: &mut V,
	) -> Quad<
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
		Term<V::Iri, V::BlankId, Literal<S, V::Iri, L>>,
	> {
		Quad(
			self.0.insert_into(vocabulary),
			self.1.insert_into(vocabulary),
			self.2.insert_into(vocabulary),
			self.3.map(|g| g.insert_into(vocabulary)),
		)
	}
Examples found in repository?
src/lib.rs (line 756)
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
	pub fn into_owned(self) -> Quad {
		Quad(
			self.0.into_owned(),
			self.1.to_owned(),
			self.2.into_owned(),
			self.3.map(GraphLabelRef::into_owned),
		)
	}
}

impl<'a> From<&'a Quad> for QuadRef<'a> {
	#[inline(always)]
	fn from(q: &'a Quad) -> Self {
		q.as_quad_ref()
	}
}

impl<'a> From<Quad<&'a Subject, &'a IriBuf, &'a Object, &'a GraphLabel>> for QuadRef<'a> {
	#[inline(always)]
	fn from(Quad(s, p, o, g): Quad<&'a Subject, &'a IriBuf, &'a Object, &'a GraphLabel>) -> Self {
		Quad(
			s.as_subject_ref(),
			p.as_iri(),
			o.as_object_ref(),
			g.map(GraphLabel::as_graph_label_ref),
		)
	}
}

/// gRDF quad.
pub type GrdfQuad = Quad<Term, Term, Term, Term>;

/// gRDF quad reference.
pub type GrdfQuadRef<'a> = Quad<TermRef<'a>, TermRef<'a>, TermRef<'a>, TermRef<'a>>;

impl<'a> GrdfQuadRef<'a> {
	#[inline(always)]
	pub fn into_owned(self) -> GrdfQuad {
		Quad(
			self.0.into_owned(),
			self.1.into_owned(),
			self.2.into_owned(),
			self.3.map(Term::into_owned),
		)
	}

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.