aws_smithy_http_server/operation/
shape.rs

1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6use std::marker::PhantomData;
7
8use super::{Handler, IntoService, Normalize, OperationService};
9use crate::shape_id::ShapeId;
10
11/// Models the [Smithy Operation shape].
12///
13/// [Smithy Operation shape]: https://smithy.io/2.0/spec/service-types.html#operation
14pub trait OperationShape {
15    /// The ID of the operation.
16    const ID: ShapeId;
17
18    /// The operation input.
19    type Input;
20    /// The operation output.
21    type Output;
22    /// The operation error. [`Infallible`](std::convert::Infallible) in the case where no error
23    /// exists.
24    type Error;
25}
26
27/// An extension trait over [`OperationShape`].
28pub trait OperationShapeExt: OperationShape {
29    /// Creates a new [`Service`](tower::Service), [`IntoService`], for well-formed [`Handler`]s.
30    fn from_handler<H, Exts>(handler: H) -> IntoService<Self, H>
31    where
32        H: Handler<Self, Exts>,
33        Self: Sized,
34    {
35        IntoService {
36            handler,
37            _operation: PhantomData,
38        }
39    }
40
41    /// Creates a new normalized [`Service`](tower::Service), [`Normalize`], for well-formed
42    /// [`Service`](tower::Service)s.
43    fn from_service<S, Exts>(svc: S) -> Normalize<Self, S>
44    where
45        S: OperationService<Self, Exts>,
46        Self: Sized,
47    {
48        Normalize {
49            inner: svc,
50            _operation: PhantomData,
51        }
52    }
53}
54
55impl<S> OperationShapeExt for S where S: OperationShape {}