aws_smithy_http_server/plugin/
stack.rs

1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6use super::{HttpMarker, ModelMarker, Plugin};
7use std::fmt::Debug;
8
9/// A wrapper struct which composes an `Inner` and an `Outer` [`Plugin`].
10///
11/// The `Inner::map` is run _then_ the `Outer::map`.
12///
13/// Note that the primary tool for composing HTTP plugins is
14/// [`HttpPlugins`](crate::plugin::HttpPlugins), and the primary tool for composing HTTP plugins is
15/// [`ModelPlugins`](crate::plugin::ModelPlugins); if you are an application writer, you should
16/// prefer composing plugins using these.
17#[derive(Debug)]
18pub struct PluginStack<Inner, Outer> {
19    inner: Inner,
20    outer: Outer,
21}
22
23impl<Inner, Outer> PluginStack<Inner, Outer> {
24    /// Creates a new [`PluginStack`].
25    pub fn new(inner: Inner, outer: Outer) -> Self {
26        PluginStack { inner, outer }
27    }
28}
29
30impl<Ser, Op, T, Inner, Outer> Plugin<Ser, Op, T> for PluginStack<Inner, Outer>
31where
32    Inner: Plugin<Ser, Op, T>,
33    Outer: Plugin<Ser, Op, Inner::Output>,
34{
35    type Output = Outer::Output;
36
37    fn apply(&self, input: T) -> Self::Output {
38        let svc = self.inner.apply(input);
39        self.outer.apply(svc)
40    }
41}
42
43impl<Inner, Outer> HttpMarker for PluginStack<Inner, Outer>
44where
45    Inner: HttpMarker,
46    Outer: HttpMarker,
47{
48}
49
50impl<Inner, Outer> ModelMarker for PluginStack<Inner, Outer>
51where
52    Inner: ModelMarker,
53    Outer: ModelMarker,
54{
55}