use crate::{__TStrRepr, TStr};
use core::{
cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd},
fmt::{Debug, Display},
hash::Hash,
};
use typewit::Identity;
macro_rules! serde_support {($($serde_bounds:tt)*) => (
pub trait IsTStr:
Identity<Type = TStr<<Self as IsTStr>::Arg>>
+ 'static
+ crate::strlike::StrLike<__TStr = Self>
+ Copy
+ Clone
+ Debug
+ Display
+ Default
+ Hash
+ Eq
+ Ord
+ PartialEq
+ PartialEq<str>
+ for<'a> PartialEq<&'a str>
+ for<'a, 'b> PartialEq<&'a &'b str>
+ PartialOrd
+ PartialOrd<str>
+ for<'a, 'b> PartialOrd<&'a &'b str>
+ Send
+ Sized
+ Sync
+ core::marker::Unpin
$($serde_bounds)*
{
type Arg: TStrArg;
const VAL: Self;
const LENGTH: usize;
const BYTES: &[u8];
const STR: &str;
fn to_tstr(self) -> TStr<Self::Arg> {
<Self as Identity>::TYPE_EQ.to_right(self)
}
fn from_tstr(tstr: TStr<Self::Arg>) -> Self {
<Self as Identity>::TYPE_EQ.to_left(tstr)
}
fn len(self) -> usize {
Self::LENGTH
}
fn to_str(self) -> &'static str {
Self::STR
}
fn to_bytes(self) -> &'static [u8] {
Self::BYTES
}
fn tstr_eq<Rhs: IsTStr>(self, rhs: Rhs) -> bool {
crate::eq(self, rhs)
}
fn tstr_ne<Rhs: IsTStr>(self, rhs: Rhs) -> bool {
crate::ne(self, rhs)
}
fn tstr_cmp<Rhs: IsTStr>(self, rhs: Rhs) -> Ordering {
crate::cmp(self, rhs)
}
fn type_eq<Rhs: IsTStr>(self, rhs: Rhs) -> typewit::TypeCmp<Self, Rhs> {
crate::type_eq(self, rhs)
}
}
)}
#[cfg(feature = "serde")]
serde_support! {+ serde::Serialize + serde::de::DeserializeOwned}
#[cfg(not(feature = "serde"))]
serde_support! {}
impl<S> IsTStr for TStr<S>
where
S: TStrArg,
{
type Arg = S;
const VAL: Self = Self::new();
const LENGTH: usize = S::__LENGTH;
const BYTES: &[u8] = S::__BYTES;
const STR: &str = S::__STR;
}
pub trait TStrArg: __TStrRepr + 'static {
#[doc(hidden)]
const __LENGTH: usize;
#[doc(hidden)]
const __BYTES: &[u8];
#[doc(hidden)]
const __STR: &str;
#[doc(hidden)]
type __WithRhs<Rhs: TStrArg>: __TStrArgBinary<Lhs = Self, Rhs = Rhs>;
#[cfg(feature = "str_generics")]
#[doc(hidden)]
type __WithLhsArgs<const LEFT_S: &'static str>: __TStrArgBinary<Lhs = crate::___<LEFT_S>, Rhs = Self>;
#[cfg(not(feature = "str_generics"))]
#[doc(hidden)]
type __WithLhsArgs<LeftS: __TStrRepr, const LEFT_LEN: usize>: __TStrArgBinary<Lhs = crate::___<LeftS, LEFT_LEN>, Rhs = Self>;
}
#[doc(hidden)]
pub trait __TStrArgBinary {
#[doc(hidden)]
type Lhs: __TStrRepr;
#[doc(hidden)]
type Rhs: __TStrRepr;
#[doc(hidden)]
const __EQ: bool;
#[doc(hidden)]
const __CMP: core::cmp::Ordering;
#[doc(hidden)]
const __TYPE_CMP: typewit::TypeCmp<crate::TStr<Self::Lhs>, crate::TStr<Self::Rhs>>;
}
pub(crate) type __ToTStrArgBinary<L, R> = <L as TStrArg>::__WithRhs<R>;
typewit::inj_type_fn! {
pub(crate) struct TStrFn;
impl<S> S => crate::TStr<S>;
}