pub use super::{impl_uri_buf_traits, impl_uri_traits};
pub use super::{rel_ref, uri, uri_ref};
#[cfg(feature = "alloc")]
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 ) => {{
$crate::assert_uri_ref_literal!($S);
$crate::_uri_const!($S, $crate::UriRef)
}};
( ) => {
$crate::uri_ref!("")
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! iuri_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 ) => {{
$crate::assert_rel_ref_literal!($S);
$crate::_uri_const!($S, $crate::RelRef)
}};
( ) => {
$crate::rel_ref!("")
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! irel_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 ) => {{
$crate::assert_uri_literal!($S);
$crate::_uri_const!($S, $crate::Uri)
}};
( ) => {
$crate::uri!("")
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! iuri {
( 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 = "alloc")]
#[macro_export]
macro_rules! uri_ref_format {
($($arg:tt)*) => ($crate::UriRefBuf::from_string(::alloc::format!($($arg)*)))
}
#[cfg(feature = "alloc")]
#[macro_export]
macro_rules! uri_format {
($($arg:tt)*) => ($crate::UriBuf::from_string(::alloc::format!($($arg)*)))
}
#[cfg(feature = "alloc")]
#[macro_export]
macro_rules! rel_ref_format {
($($arg:tt)*) => ($crate::RelRefBuf::from_string(::alloc::format!($($arg)*)))
}
#[doc(hidden)]
#[macro_export]
macro_rules! _impl_uri_traits {
( $C:ty ) => {
impl<T: ::core::convert::AsRef<str> + ?::core::marker::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: ::core::convert::AsRef<str> + ?::core::marker::Sized> ::core::cmp::PartialOrd<T>
for $C
{
fn partial_cmp(&self, other: &T) -> ::core::option::Option<::core::cmp::Ordering> {
::core::cmp::PartialOrd::partial_cmp(self.as_str(), other.as_ref())
}
}
impl ::core::cmp::Ord for $C {
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(self.as_str(), other.as_str())
}
}
impl ::core::fmt::Debug for $C {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.write_str(concat!(stringify!($C), "<"))?;
::core::fmt::Display::fmt(self.as_str(), f)?;
f.write_str(">")
}
}
impl ::core::convert::AsRef<str> for $C {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl ::core::convert::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);
#[cfg(feature = "alloc")]
impl ::core::convert::From<&$C> for ::alloc::string::String {
fn from(x: &$C) -> Self {
::alloc::string::String::from(&x.0)
}
}
#[cfg(feature = "alloc")]
impl ::core::convert::From<&$C> for $crate::UriRefBuf {
fn from(x: &$C) -> Self {
unsafe {
$crate::UriRefBuf::from_string_unchecked(::alloc::string::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) -> $crate::UriRawComponents<'_> {
self.0.components()
}
fn is_empty(&self) -> bool {
self.0.is_empty()
}
fn uri_type(&self) -> $crate::UriType {
self.0.uri_type()
}
#[cfg(feature = "alloc")]
fn to_uri_ref_buf(&self) -> $crate::UriRefBuf {
self.0.to_uri_ref_buf()
}
unsafe fn write_to_unsafe<W: ::core::fmt::Write + ?::core::marker::Sized>(
&self,
write: &mut W,
) -> ::core::fmt::Result {
self.0.write_to_unsafe(write)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! _impl_uri_buf_traits_base {
( $C:ty , $B:ty ) => {
_impl_uri_traits!($C);
#[cfg(feature = "alloc")]
impl ::core::convert::From<$C> for ::alloc::string::String {
fn from(x: $C) -> Self {
::alloc::string::String::from(x.0)
}
}
impl ::core::convert::From<&$C> for $C {
fn from(x: &$C) -> Self {
<$C as ::core::clone::Clone>::clone(x)
}
}
#[cfg(feature = "alloc")]
impl ::alloc::borrow::ToOwned for $B {
type Owned = $C;
fn to_owned(&self) -> Self::Owned {
unsafe {
<$C>::from_string_unchecked(<Self as ::alloc::string::ToString>::to_string(self))
}
}
}
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) -> $crate::UriRawComponents<'_> {
let b: &$B = <Self as ::core::borrow::Borrow<$B>>::borrow(self);
b.components()
}
fn is_empty(&self) -> bool {
let b: &$B = <Self as ::core::borrow::Borrow<$B>>::borrow(self);
b.is_empty()
}
fn uri_type(&self) -> $crate::UriType {
let b: &$B = <Self as ::core::borrow::Borrow<$B>>::borrow(self);
b.uri_type()
}
fn to_uri_ref_buf(&self) -> $crate::UriRefBuf {
let b: &$B = <Self as ::core::borrow::Borrow<$B>>::borrow(self);
b.to_uri_ref_buf()
}
unsafe fn write_to_unsafe<W: ::core::fmt::Write + ?::core::marker::Sized>(
&self,
write: &mut W,
) -> ::core::fmt::Result {
let b: &$B = <Self as ::core::borrow::Borrow<$B>>::borrow(self);
b.write_to_unsafe(write)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! impl_uri_buf_traits {
( $C:ty , $B:ty) => {
_impl_uri_buf_traits_base!($C, $B);
#[cfg(feature = "alloc")]
impl ::core::convert::AsRef<::alloc::string::String> for $C {
fn as_ref(&self) -> &::alloc::string::String {
::core::convert::AsRef::<::alloc::string::String>::as_ref(&self.0)
}
}
#[cfg(feature = "alloc")]
impl ::core::convert::AsRef<$crate::UriRefBuf> for $C {
fn as_ref(&self) -> &$crate::UriRefBuf {
::core::convert::AsRef::<$crate::UriRefBuf>::as_ref(&self.0)
}
}
#[cfg(feature = "alloc")]
impl ::core::convert::From<$C> for $crate::UriRefBuf {
fn from(x: $C) -> Self {
::core::convert::Into::<Self>::into(x.0)
}
}
};
}