uri_template_core/
__private.rs1pub use alloc::borrow::Cow;
2
3use crate::UriTemplate;
4use core::ops::Range;
5
6#[doc(hidden)]
7pub fn deconstruct_fields(this: UriTemplate) -> (Cow<'static, str>, Cow<'static, [Piece]>) {
8 (this.raw, this.pieces)
9}
10
11#[doc(hidden)]
12pub const fn from_static(raw: &'static str, pieces: &'static [Piece]) -> UriTemplate {
13 UriTemplate {
14 raw: Cow::Borrowed(raw),
15 pieces: Cow::Borrowed(pieces),
16 }
17}
18
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub enum Piece {
21 Literal(Literal),
22 Expression {
23 operator: Option<Operator>,
24 variables: Cow<'static, [Variable]>,
25 },
26}
27
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub enum Literal {
30 Fine(Range<usize>),
31 Encoded {
32 range: Range<usize>,
33 decoded: Result<Cow<'static, str>, Cow<'static, [u8]>>,
34 },
35 NeedEncode {
36 range: Range<usize>,
37 encoded: Cow<'static, str>,
38 },
39}
40
41impl Literal {
42 pub const fn range(&self) -> &Range<usize> {
43 match self {
44 Literal::Fine(range)
45 | Literal::Encoded { range, .. }
46 | Literal::NeedEncode { range, .. } => range,
47 }
48 }
49}
50
51#[derive(Debug, Clone, PartialEq, Eq)]
52pub enum Modifier {
53 Prefix(u16),
55 Explode,
57}
58
59#[derive(Debug, Clone, PartialEq, Eq)]
60pub struct Variable {
61 pub range: Range<usize>,
62 pub modifier: Option<Modifier>,
63}
64
65impl Variable {
66 pub const fn range(&self) -> &Range<usize> {
67 &self.range
68 }
69}
70
71#[derive(Debug, Clone, PartialEq, Eq)]
72pub enum Operator {
73 Plus,
75 Slash,
77 Dot,
79 Semi,
81 Question,
83 Ampersand,
85 Hash,
87 Reserved(u8),
89}