a3s_boot/routing/route/
pipeline.rs1use super::definition::RouteDefinition;
2use crate::pipeline::PipelineComponents;
3use crate::{ExceptionFilter, Guard, Interceptor, Pipe};
4use std::sync::Arc;
5
6impl RouteDefinition {
7 pub(crate) fn with_pipeline_prefix(mut self, pipeline: &PipelineComponents) -> Self {
8 self.pipes = prepend(&pipeline.pipes, self.pipes);
9 self.guards = prepend(&pipeline.guards, self.guards);
10 self.interceptors = prepend(&pipeline.interceptors, self.interceptors);
11 self.filters = prepend(&pipeline.filters, self.filters);
12 self
13 }
14
15 pub fn with_pipe<P>(mut self, pipe: P) -> Self
16 where
17 P: Pipe,
18 {
19 self.pipes.push(Arc::new(pipe));
20 self
21 }
22
23 pub fn with_guard<G>(mut self, guard: G) -> Self
24 where
25 G: Guard,
26 {
27 self.guards.push(Arc::new(guard));
28 self
29 }
30
31 pub fn with_interceptor<I>(mut self, interceptor: I) -> Self
32 where
33 I: Interceptor,
34 {
35 self.interceptors.push(Arc::new(interceptor));
36 self
37 }
38
39 pub fn with_filter<F>(mut self, filter: F) -> Self
40 where
41 F: ExceptionFilter,
42 {
43 self.filters.push(Arc::new(filter));
44 self
45 }
46}
47
48fn prepend<T>(prefix: &[Arc<T>], values: Vec<Arc<T>>) -> Vec<Arc<T>>
49where
50 T: ?Sized,
51{
52 let mut merged = prefix.to_vec();
53 merged.extend(values);
54 merged
55}