1use std::sync::Arc;
2
3use http::uri::PathAndQuery;
4
5use crate::policy::Policy;
6use crate::{BeforeFn, MapFn};
7
8#[derive(Clone)]
9pub struct RouteMeta {
10 pub service: &'static str,
11 pub route_path: &'static str,
12 pub prefix: &'static str,
13 pub rewrite: Rewrite,
14 pub policy: Arc<Policy>,
15 pub before: Option<BeforeFn>,
16 pub map: Option<MapFn>,
17}
18
19#[derive(Clone, Debug)]
20pub enum Rewrite {
21 StripPrefix,
22 Static(FixedRewrite),
23 Template(&'static RewriteTemplate),
24}
25
26#[derive(Clone, Debug)]
27pub struct FixedRewrite {
28 raw: &'static str,
29 no_query: PathAndQuery,
30}
31
32impl FixedRewrite {
33 pub fn new(raw: &'static str) -> Self {
34 Self {
35 raw,
36 no_query: PathAndQuery::from_static(raw),
37 }
38 }
39
40 #[inline]
41 pub fn raw(&self) -> &'static str {
42 self.raw
43 }
44
45 #[inline]
46 pub fn no_query(&self) -> &PathAndQuery {
47 &self.no_query
48 }
49}
50
51#[derive(Debug, Clone, Copy)]
52pub struct RewriteTemplate {
53 pub src: &'static [SrcSeg],
54 pub dst: &'static [DstChunk],
55 pub static_len: usize,
56}
57
58#[derive(Debug, Clone, Copy)]
59pub enum SrcSeg {
60 Lit(&'static str),
61 Param,
62}
63
64#[derive(Debug, Clone, Copy)]
65pub enum DstChunk {
66 Lit(&'static str),
67 Capture { src_index: u8 },
68}
69
70#[derive(Clone, Copy, Debug)]
71pub enum RewriteSpec {
72 StripPrefix,
73 Static(&'static str),
74 Template(&'static RewriteTemplate),
75}