pub use alloc::borrow::Cow;
use crate::UriTemplate;
use core::ops::Range;
#[doc(hidden)]
pub fn deconstruct_fields(this: UriTemplate) -> (Cow<'static, str>, Cow<'static, [Piece]>) {
(this.raw, this.pieces)
}
#[doc(hidden)]
pub const fn from_static(raw: &'static str, pieces: &'static [Piece]) -> UriTemplate {
UriTemplate {
raw: Cow::Borrowed(raw),
pieces: Cow::Borrowed(pieces),
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Piece {
Literal(Literal),
Expression {
operator: Option<Operator>,
variables: Cow<'static, [Variable]>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Literal {
Fine(Range<usize>),
Encoded {
range: Range<usize>,
decoded: Result<Cow<'static, str>, Cow<'static, [u8]>>,
},
NeedEncode {
range: Range<usize>,
encoded: Cow<'static, str>,
},
}
impl Literal {
pub const fn range(&self) -> &Range<usize> {
match self {
Literal::Fine(range)
| Literal::Encoded { range, .. }
| Literal::NeedEncode { range, .. } => range,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Modifier {
Prefix(u16),
Explode,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Variable {
pub range: Range<usize>,
pub modifier: Option<Modifier>,
}
impl Variable {
pub const fn range(&self) -> &Range<usize> {
&self.range
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Operator {
Plus,
Slash,
Dot,
Semi,
Question,
Ampersand,
Hash,
Reserved(u8),
}