use crate::prelude::*;
mod get;
mod set;
mod filter;
#[derive(Debug, Clone)]
pub enum MaybeQueryLike<'a> {
Query (MaybeQuery <'a>),
Fragment(MaybeFragmentQuery<'a>),
}
impl<'a> MaybeQueryLike<'a> {
pub fn new<T: Into<MaybeSpecialQuery<'a>> + Into<MaybeNonSpecialQuery<'a>> + Into<MaybeFragmentQuery<'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<MaybeSpecialQuery<'a>> + Into<MaybeNonSpecialQuery<'a>>>(value: T, r#type: QueryType) -> Self {
match r#type {
QueryType::Special => Self::new_special_query (value),
QueryType::NonSpecial => Self::new_non_special_query(value),
}
}
pub fn new_special_query <T: Into<MaybeSpecialQuery <'a>>>(value: T) -> Self {MaybeSpecialQuery ::new(value).into()}
pub fn new_non_special_query<T: Into<MaybeNonSpecialQuery<'a>>>(value: T) -> Self {MaybeNonSpecialQuery::new(value).into()}
pub fn new_fragment <T: Into<MaybeFragmentQuery <'a>>>(value: T) -> Self {MaybeFragmentQuery ::new(value).into()}
pub unsafe fn new_unchecked<T: Into<Cow<'a, str>>>(value: Option<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: Option<T>, r#type: QueryType) -> Self {
match r#type {
QueryType::Special => unsafe {Self::new_special_query_unchecked (value)},
QueryType::NonSpecial => unsafe {Self::new_non_special_query_unchecked(value)},
}
}
pub unsafe fn new_special_query_unchecked <T: Into<Cow<'a, str>>>(value: Option<T>) -> Self {unsafe {MaybeSpecialQuery ::new_unchecked(value)}.into()}
pub unsafe fn new_non_special_query_unchecked<T: Into<Cow<'a, str>>>(value: Option<T>) -> Self {unsafe {MaybeNonSpecialQuery::new_unchecked(value)}.into()}
pub unsafe fn new_fragment_unchecked <T: Into<Cow<'a, str>>>(value: Option<T>) -> Self {unsafe {MaybeFragmentQuery ::new_unchecked(value)}.into()}
pub fn as_str(&self) -> Option<&str> {
match self {
Self::Query (x) => x.as_str(),
Self::Fragment(x) => x.as_str(),
}
}
pub fn r#type(&self) -> QueryLikeType {
match self {
Self::Query (x) => x.r#type().into(),
Self::Fragment(_) => QueryLikeType::Fragment,
}
}
pub fn is_query(&self) -> bool {
matches!(self, Self::Query(_))
}
pub fn is_special_query(&self) -> bool {
matches!(self, Self::Query(MaybeQuery::Special(_)))
}
pub fn is_non_special_query(&self) -> bool {
matches!(self, Self::Query(MaybeQuery::NonSpecial(_)))
}
pub fn is_fragment(&self) -> bool {
matches!(self, Self::Fragment(_))
}
pub fn into_owned(self) -> MaybeQueryLike<'static> {
match self {
Self::Query (x) => x.into_owned().into(),
Self::Fragment(x) => x.into_owned().into(),
}
}
pub fn into_inner(self) -> Option<Cow<'a, str>> {
match self {
Self::Query (x) => x.into_inner(),
Self::Fragment(x) => x.into_inner(),
}
}
pub fn borrowed(&self) -> MaybeQueryLike<'_> {
match self {
Self::Query (x) => x.borrowed().into(),
Self::Fragment(x) => x.borrowed().into(),
}
}
}
impl<'a> From<QueryLike<'a>> for MaybeQueryLike<'a> {
fn from(value: QueryLike<'a>) -> Self {
match value {
QueryLike::Query (x) => x.into(),
QueryLike::Fragment(x) => x.into(),
}
}
}
impl<'a> From<QueryLikeSegment<'a>> for MaybeQueryLike<'a> {
fn from(value: QueryLikeSegment<'a>) -> Self {
match value {
QueryLikeSegment::Query (x) => x.into(),
QueryLikeSegment::Fragment(x) => x.into(),
}
}
}
impl<'a> From<Query <'a>> for MaybeQueryLike<'a> {fn from(value: Query <'a>) -> Self {Self::Query(value.into())}}
impl<'a> From<QuerySegment<'a>> for MaybeQueryLike<'a> {fn from(value: QuerySegment<'a>) -> Self {Self::Query(value.into())}}
impl<'a> From<Option<FragmentQuery <'a>>> for MaybeQueryLike<'a> {fn from(value: Option<FragmentQuery <'a>>) -> Self {Self::Fragment(value.into())}}
impl<'a> From<Option<Fragment <'a>>> for MaybeQueryLike<'a> {fn from(value: Option<Fragment <'a>>) -> Self {Self::Fragment(value.into())}}
impl<'a> From<Option<SpecialQuery <'a>>> for MaybeQueryLike<'a> {fn from(value: Option<SpecialQuery <'a>>) -> Self {Self::Query (value.into())}}
impl<'a> From<Option<NonSpecialQuery <'a>>> for MaybeQueryLike<'a> {fn from(value: Option<NonSpecialQuery <'a>>) -> Self {Self::Query (value.into())}}
impl<'a> From<MaybeFragmentQuery <'a>> for MaybeQueryLike<'a> {fn from(value: MaybeFragmentQuery <'a> ) -> Self {Self::Fragment(value )}}
impl<'a> From<MaybeFragment <'a>> for MaybeQueryLike<'a> {fn from(value: MaybeFragment <'a> ) -> Self {Self::Fragment(value.into())}}
impl<'a> From<MaybeQuery <'a>> for MaybeQueryLike<'a> {fn from(value: MaybeQuery <'a> ) -> Self {Self::Query (value )}}
impl<'a> From<MaybeSpecialQuery <'a>> for MaybeQueryLike<'a> {fn from(value: MaybeSpecialQuery <'a> ) -> Self {Self::Query (value.into())}}
impl<'a> From<MaybeNonSpecialQuery <'a>> for MaybeQueryLike<'a> {fn from(value: MaybeNonSpecialQuery <'a> ) -> Self {Self::Query (value.into())}}
impl<'a> From<Option<SpecialQuerySegment <'a>>> for MaybeQueryLike<'a> {fn from(value: Option<SpecialQuerySegment <'a>>) -> Self {Self::Query (value.into())}}
impl<'a> From<Option<NonSpecialQuerySegment<'a>>> for MaybeQueryLike<'a> {fn from(value: Option<NonSpecialQuerySegment<'a>>) -> Self {Self::Query (value.into())}}
impl<'a> From<Option<FragmentQuerySegment <'a>>> for MaybeQueryLike<'a> {fn from(value: Option<FragmentQuerySegment <'a>>) -> Self {Self::Fragment(value.into())}}