use crate::prelude::*;
#[derive(Debug, Clone)]
pub enum QueryLikeValue<'a> {
Query (QueryValue <'a>),
Fragment(FragmentQueryValue<'a>),
}
impl<'a> QueryLikeValue<'a> {
pub fn new<T: Into<SpecialQueryValue<'a>> + Into<NonSpecialQueryValue<'a>> + Into<FragmentQueryValue<'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<SpecialQueryValue<'a>> + Into<NonSpecialQueryValue<'a>>>(value: T, r#type: QueryType) -> Self {
QueryValue::new(value, r#type).into()
}
pub fn new_special <T: Into<SpecialQueryValue <'a>>>(value: T) -> Self {value.into().into()}
pub fn new_non_special<T: Into<NonSpecialQueryValue<'a>>>(value: T) -> Self {value.into().into()}
pub fn new_fragment <T: Into<FragmentQueryValue <'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 {QueryValue::new_unchecked(value, r#type)}.into()
}
pub unsafe fn new_special_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self {unsafe {SpecialQueryValue::new_unchecked(value)}.into()}
pub unsafe fn new_non_special_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self {unsafe {NonSpecialQueryValue::new_unchecked(value)}.into()}
pub unsafe fn new_fragment_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self {unsafe {FragmentQueryValue::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) -> QueryLikeValue<'_> {
match self {
Self::Query (x) => x.borrowed().into(),
Self::Fragment(x) => x.borrowed().into(),
}
}
pub fn into_owned(self) -> QueryLikeValue<'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<QueryValue <'a>> for QueryLikeValue<'a> {fn from(value: QueryValue <'a>) -> Self {Self::Query (value )}}
impl<'a> From<FragmentQueryValue <'a>> for QueryLikeValue<'a> {fn from(value: FragmentQueryValue <'a>) -> Self {Self::Fragment(value )}}
impl<'a> From<SpecialQueryValue <'a>> for QueryLikeValue<'a> {fn from(value: SpecialQueryValue <'a>) -> Self {Self::Query (value.into())}}
impl<'a> From<NonSpecialQueryValue<'a>> for QueryLikeValue<'a> {fn from(value: NonSpecialQueryValue<'a>) -> Self {Self::Query (value.into())}}