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
use std::convert::TryFrom;
#[cfg(feature = "serde")]
use serde::Serialize;
use validated_slice::{OwnedSliceSpec, SliceSpec};
use crate::{
types::{IriCreationError, IriReferenceStr, IriReferenceString, IriStr, IriString},
validate::iri::{absolute_iri, Error},
};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
#[allow(clippy::derive_hash_xor_eq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct AbsoluteIriStr(str);
impl AbsoluteIriStr {
pub fn new(s: &str) -> Result<&Self, Error> {
TryFrom::try_from(s)
}
pub(crate) unsafe fn new_unchecked(s: &str) -> &Self {
debug_assert_eq!(StrSpec::validate(s), Ok(()));
StrSpec::from_inner_unchecked(s)
}
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct AbsoluteIriString(String);
impl AbsoluteIriString {
pub(crate) unsafe fn new_unchecked(s: String) -> Self {
debug_assert_eq!(StrSpec::validate(&s), Ok(()));
StringSpec::from_inner_unchecked(s)
}
#[inline]
pub fn shrink_to_fit(&mut self) {
self.0.shrink_to_fit()
}
}
impl_basics! {
Slice {
spec: StrSpec,
custom: AbsoluteIriStr,
validator: absolute_iri,
error: Error,
},
Owned {
spec: StringSpec,
custom: AbsoluteIriString,
error: IriCreationError<String>,
},
}
impl std::ops::Deref for AbsoluteIriStr {
type Target = IriStr;
fn deref(&self) -> &Self::Target {
self.as_ref()
}
}
impl_conv_and_cmp! {
source: {
owned: AbsoluteIriString,
slice: AbsoluteIriStr,
creation_error: IriCreationError,
validation_error: Error,
},
target: [
{
owned: IriString,
slice: IriStr,
},
{
owned: IriReferenceString,
slice: IriReferenceStr,
},
],
}
impl_serde! {
expecting: "an absolute IRI",
slice: AbsoluteIriStr,
owned: AbsoluteIriString,
}