use crate::prelude::*;
mod get;
mod set;
mod filter;
#[derive(Debug, Clone)]
pub enum MaybeQuery<'a> {
Special (MaybeSpecialQuery <'a>),
NonSpecial(MaybeNonSpecialQuery<'a>),
}
impl<'a> MaybeQuery<'a> {
pub fn new<T: Into<MaybeSpecialQuery<'a>> + Into<MaybeNonSpecialQuery<'a>>>(value: T, r#type: QueryType) -> Self {
match r#type {
QueryType::Special => Self::new_special (value),
QueryType::NonSpecial => Self::new_non_special(value),
}
}
pub fn new_special <T: Into<MaybeSpecialQuery <'a>>>(query: T) -> Self {MaybeSpecialQuery ::new(query).into()}
pub fn new_non_special<T: Into<MaybeNonSpecialQuery<'a>>>(query: T) -> Self {MaybeNonSpecialQuery::new(query).into()}
pub unsafe fn new_unchecked<T: Into<Cow<'a, str>>>(value: Option<T>, r#type: QueryType) -> Self {
unsafe {
match r#type {
QueryType::Special => Self::new_special_unchecked (value),
QueryType::NonSpecial => Self::new_non_special_unchecked(value),
}
}
}
pub unsafe fn new_special_unchecked<T: Into<Cow<'a, str>>>(value: Option<T>) -> Self {
unsafe {MaybeSpecialQuery::new_unchecked(value).into()}
}
pub unsafe fn new_non_special_unchecked<T: Into<Cow<'a, str>>>(value: Option<T>) -> Self {
unsafe {MaybeNonSpecialQuery::new_unchecked(value).into()}
}
pub fn as_str(&self) -> Option<&str> {
match self {
Self::Special (x) => x.as_str(),
Self::NonSpecial(x) => x.as_str(),
}
}
pub fn search_len(&self) -> usize {
self.len().map_or(0, |x| x + 1)
}
pub fn r#type(&self) -> QueryType {
match self {
Self::Special (_) => QueryType::Special ,
Self::NonSpecial(_) => QueryType::NonSpecial,
}
}
pub fn is_special(&self) -> bool {
matches!(self, Self::Special(_))
}
pub fn is_non_special(&self) -> bool {
matches!(self, Self::NonSpecial(_))
}
pub fn is_some(&self) -> bool {
match self {
Self::Special (x) => x.is_some(),
Self::NonSpecial(x) => x.is_some(),
}
}
pub fn is_none(&self) -> bool {
match self {
Self::Special (x) => x.is_none(),
Self::NonSpecial(x) => x.is_none(),
}
}
pub fn borrowed(&self) -> MaybeQuery<'_> {
match self {
Self::Special (x) => x.borrowed().into(),
Self::NonSpecial(x) => x.borrowed().into(),
}
}
pub fn into_owned(self) -> MaybeQuery<'static> {
match self {
Self::Special (x) => x.into_owned().into(),
Self::NonSpecial(x) => x.into_owned().into(),
}
}
pub fn into_inner(self) -> Option<Cow<'a, str>> {
match self {
Self::Special (x) => x.into_inner(),
Self::NonSpecial(x) => x.into_inner(),
}
}
}
impl<'a> TryFrom<QueryLike<'a>> for MaybeQuery<'a> {
type Error = FragmentQuery<'a>;
fn try_from(value: QueryLike<'a>) -> Result<Self, Self::Error> {
match value {
QueryLike::Query (x) => Ok (x.into()),
QueryLike::Fragment(x) => Err(x )
}
}
}
impl<'a> From<Query<'a>> for MaybeQuery<'a> {
fn from(value: Query<'a>) -> Self {
match value {
Query::Special (x) => Self::Special (x.into()),
Query::NonSpecial(x) => Self::NonSpecial(x.into()),
}
}
}
impl<'a> TryFrom<QueryLikeSegment<'a>> for MaybeQuery<'a> {
type Error = FragmentQuerySegment<'a>;
fn try_from(value: QueryLikeSegment<'a>) -> Result<Self, Self::Error> {
match value {
QueryLikeSegment::Query (x) => Ok (x.into()),
QueryLikeSegment::Fragment(x) => Err(x ),
}
}
}
impl<'a> From<QuerySegment<'a>> for MaybeQuery<'a> {
fn from(value: QuerySegment<'a>) -> Self {
match value {
QuerySegment::Special (x) => Self::Special (x.into()),
QuerySegment::NonSpecial(x) => Self::NonSpecial(x.into()),
}
}
}
impl<'a> From<MaybeSpecialQuery <'a> > for MaybeQuery<'a> {fn from(value: MaybeSpecialQuery <'a> ) -> Self {Self::Special (value )}}
impl<'a> From<MaybeNonSpecialQuery <'a> > for MaybeQuery<'a> {fn from(value: MaybeNonSpecialQuery <'a> ) -> Self {Self::NonSpecial(value )}}
impl<'a> From<Option<SpecialQuery <'a>>> for MaybeQuery<'a> {fn from(value: Option<SpecialQuery <'a>>) -> Self {Self::Special (value.into())}}
impl<'a> From<Option<NonSpecialQuery <'a>>> for MaybeQuery<'a> {fn from(value: Option<NonSpecialQuery <'a>>) -> Self {Self::NonSpecial(value.into())}}
impl<'a> From<Option<SpecialQuerySegment <'a>>> for MaybeQuery<'a> {fn from(value: Option<SpecialQuerySegment <'a>>) -> Self {Self::Special (value.into())}}
impl<'a> From<Option<NonSpecialQuerySegment<'a>>> for MaybeQuery<'a> {fn from(value: Option<NonSpecialQuerySegment<'a>>) -> Self {Self::NonSpecial(value.into())}}