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