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
use std::fmt;
pub trait RdfDisplay {
fn rdf_fmt(&self, f: &mut fmt::Formatter) -> fmt::Result;
fn rdf_display(&self) -> RdfDisplayed<&Self> {
RdfDisplayed(self)
}
}
impl<'a, T: RdfDisplay + ?Sized> RdfDisplay for &'a T {
fn rdf_fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
T::rdf_fmt(*self, f)
}
}
pub struct RdfDisplayed<T>(T);
impl<T: RdfDisplay> fmt::Display for RdfDisplayed<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.rdf_fmt(f)
}
}
#[cfg(feature = "contextual")]
pub trait RdfDisplayWithContext<C: ?Sized> {
fn rdf_fmt_with(&self, context: &C, f: &mut fmt::Formatter) -> fmt::Result;
}
#[cfg(feature = "contextual")]
impl<'a, T: RdfDisplayWithContext<C> + ?Sized, C: ?Sized> RdfDisplayWithContext<C> for &'a T {
fn rdf_fmt_with(&self, context: &C, f: &mut fmt::Formatter) -> fmt::Result {
T::rdf_fmt_with(*self, context, f)
}
}
#[cfg(feature = "contextual")]
impl<'c, T: RdfDisplayWithContext<C>, C: ?Sized> RdfDisplay for contextual::Contextual<T, &'c C> {
fn rdf_fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.rdf_fmt_with(self.1, f)
}
}
#[cfg(feature = "contextual")]
impl<'c, T: RdfDisplayWithContext<C>, C: ?Sized> RdfDisplay
for contextual::Contextual<T, &'c mut C>
{
fn rdf_fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.rdf_fmt_with(self.1, f)
}
}