use crate::prelude::*;
#[derive(Debug, Clone)]
pub enum QueryLikeName<'a> {
Query (QueryName <'a>),
Fragment(FragmentQueryName<'a>),
}
impl<'a> QueryLikeName<'a> {
pub fn new<T: Into<SpecialQueryName<'a>> + Into<NonSpecialQueryName<'a>> + Into<FragmentQueryName<'a>>>(value: T, r#type: QueryLikeType) -> Self {
match r#type {
QueryLikeType::Query (r#type) => Self::new_query (value, r#type),
QueryLikeType::Fragment => Self::new_fragment(value ),
}
}
pub fn new_query<T: Into<SpecialQueryName<'a>> + Into<NonSpecialQueryName<'a>>>(value: T, r#type: QueryType) -> Self {
QueryName::new(value, r#type).into()
}
pub fn new_special <T: Into<SpecialQueryName <'a>>>(value: T) -> Self {value.into().into()}
pub fn new_non_special<T: Into<NonSpecialQueryName<'a>>>(value: T) -> Self {value.into().into()}
pub fn new_fragment <T: Into<FragmentQueryName <'a>>>(value: T) -> Self {value.into().into()}
pub unsafe fn new_unchecked<T: Into<Cow<'a, str>>>(value: T, r#type: QueryLikeType) -> Self {
match r#type {
QueryLikeType::Query (r#type) => unsafe {Self::new_query_unchecked (value, r#type)},
QueryLikeType::Fragment => unsafe {Self::new_fragment_unchecked(value )},
}
}
pub unsafe fn new_query_unchecked<T: Into<Cow<'a, str>>>(value: T, r#type: QueryType) -> Self {
unsafe {QueryName::new_unchecked(value, r#type)}.into()
}
pub unsafe fn new_special_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self {unsafe {SpecialQueryName::new_unchecked(value)}.into()}
pub unsafe fn new_non_special_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self {unsafe {NonSpecialQueryName::new_unchecked(value)}.into()}
pub unsafe fn new_fragment_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self {unsafe {FragmentQueryName::new_unchecked(value)}.into()}
pub fn as_str(&self) -> &str {
match self {
Self::Query (x) => x.as_str(),
Self::Fragment(x) => x.as_str(),
}
}
pub fn decode(self) -> Cow<'a, [u8]> {
match self {
Self::Query (x) => x.decode(),
Self::Fragment(x) => x.decode(),
}
}
pub fn try_decode(self) -> Result<Cow<'a, str>, (std::str::Utf8Error, Cow<'a, [u8]>)> {
match self {
Self::Query (x) => x.try_decode(),
Self::Fragment(x) => x.try_decode(),
}
}
pub fn lossy_decode(self) -> Cow<'a, str> {
match self {
Self::Query (x) => x.lossy_decode(),
Self::Fragment(x) => x.lossy_decode(),
}
}
pub fn borrowed(&self) -> QueryLikeName<'_> {
match self {
Self::Query (x) => x.borrowed().into(),
Self::Fragment(x) => x.borrowed().into(),
}
}
pub fn into_owned(self) -> QueryLikeName<'static> {
match self {
Self::Query (x) => x.into_owned().into(),
Self::Fragment(x) => x.into_owned().into(),
}
}
pub fn into_inner(self) -> Cow<'a, str> {
match self {
Self::Query (x) => x.into_inner(),
Self::Fragment(x) => x.into_inner(),
}
}
}
impl<'a> From<QueryName <'a>> for QueryLikeName<'a> {fn from(value: QueryName <'a>) -> Self {Self::Query (value )}}
impl<'a> From<FragmentQueryName <'a>> for QueryLikeName<'a> {fn from(value: FragmentQueryName <'a>) -> Self {Self::Fragment(value )}}
impl<'a> From<SpecialQueryName <'a>> for QueryLikeName<'a> {fn from(value: SpecialQueryName <'a>) -> Self {Self::Query (value.into())}}
impl<'a> From<NonSpecialQueryName<'a>> for QueryLikeName<'a> {fn from(value: NonSpecialQueryName<'a>) -> Self {Self::Query (value.into())}}