use crate::prelude::*;
mod name;
mod value;
#[derive(Debug, Clone)]
pub enum QuerySegment<'a> {
Special (SpecialQuerySegment <'a>),
NonSpecial(NonSpecialQuerySegment<'a>),
}
impl<'a> QuerySegment<'a> {
pub fn r#type(&self) -> QueryType {
match self {
Self::Special (_) => QueryType::Special ,
Self::NonSpecial(_) => QueryType::NonSpecial,
}
}
pub fn as_str(&self) -> &str {
match self {
Self::Special (x) => x.as_str(),
Self::NonSpecial(x) => x.as_str(),
}
}
pub fn new<T: Into<SpecialQuerySegment<'a>> + Into<NonSpecialQuerySegment<'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<SpecialQuerySegment <'a>>>(value: T) -> Self {SpecialQuerySegment ::new(value).into()}
pub fn new_non_special<T: Into<NonSpecialQuerySegment<'a>>>(value: T) -> Self {NonSpecialQuerySegment::new(value).into()}
pub unsafe fn new_unchecked<T: Into<Cow<'a, str>>>(value: 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: T) -> Self {
unsafe {
SpecialQuerySegment::new_unchecked(value).into()
}
}
pub unsafe fn new_non_special_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self {
unsafe {
NonSpecialQuerySegment::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) -> QuerySegment<'_> {
match self {
Self::Special (x) => x.borrowed().into(),
Self::NonSpecial(x) => x.borrowed().into(),
}
}
pub fn into_owned(self) -> QuerySegment<'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(),
}
}
pub fn into_parts(self) -> (Cow<'a, str>, Option<NonZero<usize>>) {
match self {
Self::Special (x) => x.into_parts(),
Self::NonSpecial(x) => x.into_parts(),
}
}
}
impl<'a> TryFrom<QueryLikeSegment<'a>> for QuerySegment<'a> {
type Error = FragmentQuerySegment<'a>;
fn try_from(value: QueryLikeSegment<'a>) -> Result<Self, Self::Error> {
match value {
QueryLikeSegment::Query (x) => Ok (x),
QueryLikeSegment::Fragment(x) => Err(x),
}
}
}
impl<'a> From<SpecialQuerySegment <'a>> for QuerySegment<'a> {fn from(value: SpecialQuerySegment <'a>) -> Self {Self::Special (value)}}
impl<'a> From<NonSpecialQuerySegment<'a>> for QuerySegment<'a> {fn from(value: NonSpecialQuerySegment<'a>) -> Self {Self::NonSpecial(value)}}