use crate::prelude::*;
#[derive(Debug, Clone)]
pub struct SpecialQueryName<'a>(Cow<'a, str>);
impl<'a> SpecialQueryName<'a> {
pub unsafe fn new_unchecked<T: Into<Cow<'a, str>>>(value: T) -> Self {
Self(value.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
pub fn decode(self) -> Cow<'a, [u8]> {
let (_, value) = decode_query_part(self.0);
value
}
pub fn try_decode(self) -> Result<Cow<'a, str>, (std::str::Utf8Error, Cow<'a, [u8]>)> {
let (_, value) = try_decode_query_part(self.0)?;
Ok(value)
}
pub fn lossy_decode(self) -> Cow<'a, str> {
let (_, value) = lossy_decode_query_part(self.0);
value
}
pub fn borrowed(&self) -> SpecialQueryName<'_> {
SpecialQueryName(self.as_str().into())
}
pub fn into_owned(self) -> SpecialQueryName<'static> {
SpecialQueryName(self.0.into_owned().into())
}
pub fn into_inner(self) -> Cow<'a, str> {
self.0
}
}
impl<'a> From<Cow<'a, [u8]>> for SpecialQueryName<'a> {
fn from(value: Cow<'a, [u8]>) -> Self {
let (_, value) = encode_query_part_bytes(value);
unsafe {
Self::new_unchecked(value)
}
}
}
impl<'a> From<QueryLikeName<'a>> for SpecialQueryName<'a> {
fn from(value: QueryLikeName<'a>) -> Self {
match value {
QueryLikeName::Query (x) => x.into(),
QueryLikeName::Fragment(x) => x.into(),
}
}
}
impl<'a> From<QueryName<'a>> for SpecialQueryName<'a> {
fn from(value: QueryName<'a>) -> Self {
match value {
QueryName::Special (x) => x,
QueryName::NonSpecial(x) => x.into(),
}
}
}
impl<'a> From<FragmentQueryName <'a>> for SpecialQueryName<'a> {fn from(value: FragmentQueryName <'a>) -> Self {unsafe {Self::new_unchecked(fragment_to_non_special_query (value.into_inner()).1)}}}
impl<'a> From<NonSpecialQueryName<'a>> for SpecialQueryName<'a> {fn from(value: NonSpecialQueryName<'a>) -> Self {unsafe {Self::new_unchecked(non_special_query_to_special_query(value.into_inner()).1)}}}