pub use super::{impl_uri_buf_traits, impl_uri_traits};
pub use super::{rel_ref, uri, uri_ref};
pub use super::{rel_ref_format, uri_format, uri_ref_format};
#[doc(hidden)]
pub use super::{_impl_uri_buf_traits_base, _impl_uri_traits, _impl_uri_traits_base};
#[doc(hidden)]
#[macro_export]
macro_rules! _uri_const {
( $S:expr, $C:ty ) => {{
const __CONST_S: &'static str = $S;
unsafe {
union Slices<'a> {
str: &'a str,
uri: &'a $C,
}
Slices { str: __CONST_S }.uri
}
}};
}
#[macro_export]
macro_rules! uri_ref {
( unsafe $S:expr ) => {{
$crate::_uri_const!($S, $crate::UriRef)
}};
( $S:expr ) => {{
assert_uri_ref_literal!($S);
$crate::_uri_const!($S, $crate::UriRef)
}};
( ) => {
$crate::uri_ref!("")
};
}
#[macro_export]
macro_rules! rel_ref {
( unsafe $S:expr ) => {{
$crate::_uri_const!($S, $crate::RelRef)
}};
( $S:expr ) => {{
assert_rel_ref_literal!($S);
$crate::_uri_const!($S, $crate::RelRef)
}};
( ) => {
$crate::rel_ref!("")
};
}
#[macro_export]
macro_rules! uri {
( unsafe $S:expr ) => {{
$crate::_uri_const!($S, $crate::Uri)
}};
( $S:expr ) => {{
assert_uri_literal!($S);
$crate::_uri_const!($S, $crate::Uri)
}};
( ) => {
$crate::uri!("")
};
}
#[cfg(feature = "std")]
#[macro_export]
macro_rules! uri_ref_format {
($($arg:tt)*) => ($crate::UriRefBuf::from_string(format!($($arg)*)))
}
#[cfg(feature = "std")]
#[macro_export]
macro_rules! uri_format {
($($arg:tt)*) => ($crate::UriBuf::from_string(format!($($arg)*)))
}
#[cfg(feature = "std")]
#[macro_export]
macro_rules! rel_ref_format {
($($arg:tt)*) => ($crate::RelRefBuf::from_string(format!($($arg)*)))
}
#[doc(hidden)]
#[macro_export]
macro_rules! _impl_uri_traits {
( $C:ty ) => {
impl<T: AsRef<str> + ?Sized> core::cmp::PartialEq<T> for $C {
fn eq(&self, other: &T) -> bool {
core::cmp::PartialEq::eq(self.as_str(), other.as_ref())
}
}
impl<T: AsRef<str> + ?Sized> core::cmp::PartialOrd<T> for $C {
fn partial_cmp(&self, other: &T) -> Option<::std::cmp::Ordering> {
core::cmp::PartialOrd::partial_cmp(self.as_str(), other.as_ref())
}
}
impl core::cmp::Ord for $C {
fn cmp(&self, other: &Self) -> ::std::cmp::Ordering {
core::cmp::Ord::cmp(self.as_str(), other.as_str())
}
}
impl std::fmt::Debug for $C {
fn fmt(
&self,
f: &mut std::fmt::Formatter<'_>,
) -> std::result::Result<(), std::fmt::Error> {
f.write_str(concat!(stringify!($C), "<"))?;
std::fmt::Display::fmt(self.as_str(), f)?;
f.write_str(">")
}
}
impl AsRef<str> for $C {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl AsRef<$C> for $C {
fn as_ref(&self) -> &$C {
&self
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! _impl_uri_traits_base {
( $C:ty ) => {
_impl_uri_traits!($C);
impl core::convert::From<&$C> for std::string::String {
fn from(x: &$C) -> Self {
String::from(&x.0)
}
}
impl core::convert::From<&$C> for $crate::UriRefBuf {
fn from(x: &$C) -> Self {
unsafe { $crate::UriRefBuf::from_string_unchecked(String::from(&x.0)) }
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! impl_uri_traits {
( $C:ty ) => {
_impl_uri_traits_base!($C);
impl $crate::AnyUriRef for $C {
fn components(&self) -> UriRawComponents<'_> {
self.0.components()
}
fn write_to<W: core::fmt::Write + ?Sized>(
&self,
write: &mut W,
) -> Result<(), core::fmt::Error> {
self.0.write_to(write)
}
fn is_empty(&self) -> bool {
self.0.is_empty()
}
fn uri_type(&self) -> $crate::UriType {
self.0.uri_type()
}
fn to_uri_ref_buf(&self) -> $crate::UriRefBuf {
self.0.to_uri_ref_buf()
}
fn write_resolved<W: core::fmt::Write + ?Sized, D: $crate::AnyUriRef + ?Sized>(
&self,
dest: &D,
output: &mut W,
) -> Result<(), $crate::ResolveError> {
self.0.write_resolved(dest, output)
}
fn resolved<W: $crate::AnyUriRef + ?Sized>(
&self,
dest: &W,
) -> Result<$crate::UriRefBuf, $crate::ResolveError> {
self.0.resolved(dest)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! _impl_uri_buf_traits_base {
( $C:ty , $B:ty ) => {
_impl_uri_traits!($C);
impl core::convert::From<$C> for std::string::String {
fn from(x: $C) -> Self {
String::from(x.0)
}
}
impl core::convert::From<&$C> for $C {
fn from(x: &$C) -> Self {
x.clone()
}
}
impl std::borrow::ToOwned for $B {
type Owned = $C;
fn to_owned(&self) -> Self::Owned {
unsafe { <$C>::from_string_unchecked(self.to_string()) }
}
}
impl core::borrow::Borrow<$B> for $C {
fn borrow(&self) -> &$B {
unsafe { <$B>::from_str_unchecked(self.as_str()) }
}
}
impl $crate::AnyUriRef for $C {
fn components(&self) -> UriRawComponents<'_> {
use core::borrow::Borrow;
let b: &$B = self.borrow();
b.components()
}
fn write_to<W: core::fmt::Write + ?Sized>(
&self,
write: &mut W,
) -> Result<(), core::fmt::Error> {
use core::borrow::Borrow;
let b: &$B = self.borrow();
b.write_to(write)
}
fn is_empty(&self) -> bool {
use core::borrow::Borrow;
let b: &$B = self.borrow();
b.is_empty()
}
fn uri_type(&self) -> $crate::UriType {
use core::borrow::Borrow;
let b: &$B = self.borrow();
b.uri_type()
}
fn to_uri_ref_buf(&self) -> $crate::UriRefBuf {
use core::borrow::Borrow;
let b: &$B = self.borrow();
b.to_uri_ref_buf()
}
fn write_resolved<W: core::fmt::Write + ?Sized, D: $crate::AnyUriRef + ?Sized>(
&self,
dest: &D,
output: &mut W,
) -> Result<(), $crate::ResolveError> {
use core::borrow::Borrow;
let b: &$B = self.borrow();
b.write_resolved(dest, output)
}
fn resolved<W: $crate::AnyUriRef + ?Sized>(
&self,
dest: &W,
) -> Result<$crate::UriRefBuf, $crate::ResolveError> {
use core::borrow::Borrow;
let b: &$B = self.borrow();
b.resolved(dest)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! impl_uri_buf_traits {
( $C:ty , $B:ty) => {
_impl_uri_buf_traits_base!($C, $B);
impl AsRef<std::string::String> for $C {
fn as_ref(&self) -> &std::string::String {
AsRef::<std::string::String>::as_ref(&self.0)
}
}
impl AsRef<$crate::UriRefBuf> for $C {
fn as_ref(&self) -> &$crate::UriRefBuf {
AsRef::<$crate::UriRefBuf>::as_ref(&self.0)
}
}
impl core::convert::From<$C> for $crate::UriRefBuf {
fn from(x: $C) -> Self {
x.0.into()
}
}
};
}