use crate::{IsTStr, TStr};
use typewit::{Identity, TypeEq};
#[doc(hidden)]
pub trait __StrLikeBase {
#[doc(hidden)]
type __Kind;
}
pub trait StrLike: __AsStrLike<Target = Self> + __StrLikeBase<__Kind = __StrKind> {
#[doc(hidden)]
type __TStr: IsTStr;
#[doc(hidden)]
const __STR_LIKE_WITNESS: __StrLikeWitness<Self>;
fn as_str(&self) -> &str {
as_str!(self)
}
}
#[doc(hidden)]
pub enum __StrKind {}
#[doc(hidden)]
pub enum __RefKind {}
impl<T: ?Sized> __StrLikeBase for &T {
type __Kind = __RefKind;
}
impl __StrLikeBase for str {
type __Kind = __StrKind;
}
impl StrLike for str {
#[doc(hidden)]
type __TStr = crate::__Empty;
#[doc(hidden)]
const __STR_LIKE_WITNESS: __StrLikeWitness<Self> = __StrLikeWitness::Str(TypeEq::NEW);
}
impl<S: crate::TStrArg> __StrLikeBase for TStr<S> {
type __Kind = __StrKind;
}
impl<S: crate::IsTStr> StrLike for S {
#[doc(hidden)]
type __TStr = S;
#[doc(hidden)]
const __STR_LIKE_WITNESS: __StrLikeWitness<Self> =
__StrLikeWitness::TStr(<S as Identity>::TYPE_EQ);
}
#[diagnostic::on_unimplemented(
message = "`StrLike` is not implemented for `{T}`",
label = "`tstr::strlike::StrLike` is not implemented for `{T}`",
note = "help:\nconsider adding a `{T}: ?Sized + tstr::strlike::StrLike` bound\n"
)]
#[doc(hidden)]
pub trait __use_StrLike_instead_of_this_trait<__, Kind, T: ?Sized> {
#[doc(hidden)]
type Target: StrLike + ?Sized;
}
#[diagnostic::on_unimplemented(
message = "`StrLike` is not implemented for `{Self}`",
label = "`tstr::strlike::StrLike` is not implemented for `{Self}`",
note = "help:\nconsider adding a `{Self}: ?Sized + tstr::strlike::StrLike` bound\n"
)]
#[doc(hidden)]
pub trait __AsStrLike {
#[doc(hidden)]
type Target: StrLike + ?Sized;
}
#[diagnostic::do_not_recommend]
impl<T: ?Sized + __AsStrLike> __use_StrLike_instead_of_this_trait<(), __RefKind, &T> for () {
type Target = T::Target;
}
#[diagnostic::do_not_recommend]
impl __use_StrLike_instead_of_this_trait<(), __StrKind, str> for () {
type Target = str;
}
#[diagnostic::do_not_recommend]
impl<S: IsTStr> __use_StrLike_instead_of_this_trait<(), __StrKind, S> for () {
type Target = S;
}
#[diagnostic::do_not_recommend]
impl<T> __AsStrLike for T
where
T: ?Sized + __StrLikeBase,
(): __use_StrLike_instead_of_this_trait<(), <T as __StrLikeBase>::__Kind, T>,
{
type Target =
<() as __use_StrLike_instead_of_this_trait<(), <T as __StrLikeBase>::__Kind, T>>::Target;
}
#[doc(inline)]
pub use crate::__as_str as as_str;
#[doc(hidden)]
#[macro_export]
macro_rules! __as_str {
($reff:expr) => {
match &$reff {
reff => $crate::strlike::__as_str_fn(reff, reff),
}
};
}
type ACToTstr<T> = TStr<<<T as StrLike>::__TStr as IsTStr>::Arg>;
#[doc(hidden)]
pub enum __StrLikeWitness<T: ?Sized + StrLike> {
Str(TypeEq<T, str>),
TStr(TypeEq<T, ACToTstr<T>>),
}
#[doc(hidden)]
pub const fn __as_str_fn<'a, D: ?Sized + __AsStrLike>(_: &D, this: &'a D::Target) -> &'a str {
match <D::Target>::__STR_LIKE_WITNESS {
__StrLikeWitness::Str(te) => te.in_ref().to_right(this),
__StrLikeWitness::TStr(te) => crate::to_str(*te.in_ref().to_right(this)),
}
}