1use crate::spec::UriSpec;
4use crate::types::{
5 IriAbsoluteStr, IriFragmentStr, IriQueryStr, IriReferenceStr, IriRelativeStr, IriStr,
6 RiAbsoluteStr, RiFragmentStr, RiQueryStr, RiReferenceStr, RiRelativeStr, RiStr,
7};
8#[cfg(feature = "alloc")]
9use crate::types::{
10 IriAbsoluteString, IriFragmentString, IriQueryString, IriReferenceString, IriRelativeString,
11 IriString, RiAbsoluteString, RiFragmentString, RiQueryString, RiReferenceString,
12 RiRelativeString, RiString,
13};
14
15pub type UriAbsoluteStr = RiAbsoluteStr<UriSpec>;
17
18#[cfg(feature = "alloc")]
20pub type UriAbsoluteString = RiAbsoluteString<UriSpec>;
21
22pub type UriFragmentStr = RiFragmentStr<UriSpec>;
24
25#[cfg(feature = "alloc")]
27pub type UriFragmentString = RiFragmentString<UriSpec>;
28
29pub type UriStr = RiStr<UriSpec>;
31
32#[cfg(feature = "alloc")]
34pub type UriString = RiString<UriSpec>;
35
36pub type UriReferenceStr = RiReferenceStr<UriSpec>;
38
39#[cfg(feature = "alloc")]
41pub type UriReferenceString = RiReferenceString<UriSpec>;
42
43pub type UriRelativeStr = RiRelativeStr<UriSpec>;
45
46#[cfg(feature = "alloc")]
48pub type UriRelativeString = RiRelativeString<UriSpec>;
49
50pub type UriQueryStr = RiQueryStr<UriSpec>;
52
53#[cfg(feature = "alloc")]
55pub type UriQueryString = RiQueryString<UriSpec>;
56
57macro_rules! impl_conversions_between_iri {
59 (
60 $borrowed_uri:ident,
61 $owned_uri:ident,
62 $borrowed_iri:ident,
63 $owned_iri:ident,
64 ) => {
65 impl AsRef<$borrowed_iri> for $borrowed_uri {
66 fn as_ref(&self) -> &$borrowed_iri {
67 unsafe {
69 <$borrowed_iri>::new_unchecked_justified(
70 self.as_str(),
71 "a valid URI is also a valid IRI",
72 )
73 }
74 }
75 }
76
77 #[cfg(feature = "alloc")]
78 impl From<$owned_uri> for $owned_iri {
79 #[inline]
80 fn from(uri: $owned_uri) -> Self {
81 unsafe {
83 Self::new_unchecked_justified(uri.into(), "a valid URI is also a valid IRI")
84 }
85 }
86 }
87
88 #[cfg(feature = "alloc")]
89 impl AsRef<$borrowed_iri> for $owned_uri {
90 fn as_ref(&self) -> &$borrowed_iri {
91 AsRef::<$borrowed_uri>::as_ref(self).as_ref()
92 }
93 }
94 };
95}
96
97impl_conversions_between_iri!(
98 UriAbsoluteStr,
99 UriAbsoluteString,
100 IriAbsoluteStr,
101 IriAbsoluteString,
102);
103impl_conversions_between_iri!(
104 UriReferenceStr,
105 UriReferenceString,
106 IriReferenceStr,
107 IriReferenceString,
108);
109impl_conversions_between_iri!(
110 UriRelativeStr,
111 UriRelativeString,
112 IriRelativeStr,
113 IriRelativeString,
114);
115impl_conversions_between_iri!(UriStr, UriString, IriStr, IriString,);
116impl_conversions_between_iri!(UriQueryStr, UriQueryString, IriQueryStr, IriQueryString,);
117impl_conversions_between_iri!(
118 UriFragmentStr,
119 UriFragmentString,
120 IriFragmentStr,
121 IriFragmentString,
122);