aws_smithy_http_server/
service.rs

1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6//! The shape of a [Smithy service] is modelled by the [`ServiceShape`] trait. Its associated types
7//! [`ServiceShape::ID`], [`ServiceShape::VERSION`], [`ServiceShape::Protocol`], and [`ServiceShape::Operations`] map
8//! to the services [Shape ID](https://smithy.io/2.0/spec/model.html#shape-id), the version field, the applied
9//! [protocol trait](https://smithy.io/2.0/aws/protocols/index.html) (see [`protocol`](crate::protocol) module), and the
10//! operations field.
11//!
12//! We generate an implementation on this for every service struct (exported from the root of the generated crate).
13//!
14//! As stated in the [operation module documentation](crate::operation) we also generate marker structs for
15//! [`OperationShape`](crate::operation::OperationShape), these are coupled to the `S: ServiceShape` via the [`ContainsOperation`] trait.
16//!
17//! The model
18//!
19//! ```smithy
20//! @restJson1
21//! service Shopping {
22//!     version: "1.0",
23//!     operations: [
24//!         GetShopping,
25//!         PutShopping
26//!     ]
27//! }
28//! ```
29//!
30//! is identified with the implementation
31//!
32//! ```rust,no_run
33//! # use aws_smithy_http_server::shape_id::ShapeId;
34//! # use aws_smithy_http_server::service::{ServiceShape, ContainsOperation};
35//! # use aws_smithy_http_server::protocol::rest_json_1::RestJson1;
36//! # pub struct Shopping;
37//! // For more information on these marker structs see `OperationShape`
38//! struct GetShopping;
39//! struct PutShopping;
40//!
41//! // This is a generated enumeration of all operations.
42//! #[derive(PartialEq, Eq, Clone, Copy)]
43//! pub enum Operation {
44//!     GetShopping,
45//!     PutShopping
46//! }
47//!
48//! impl ServiceShape for Shopping {
49//!     const ID: ShapeId = ShapeId::new("namespace#Shopping", "namespace", "Shopping");
50//!     const VERSION: Option<&'static str> = Some("1.0");
51//!     type Protocol = RestJson1;
52//!     type Operations = Operation;
53//! }
54//!
55//! impl ContainsOperation<GetShopping> for Shopping {
56//!     const VALUE: Operation = Operation::GetShopping;
57//! }
58//!
59//! impl ContainsOperation<PutShopping> for Shopping {
60//!     const VALUE: Operation = Operation::PutShopping;
61//! }
62//! ```
63//!
64//! [Smithy service]: https://smithy.io/2.0/spec/service-types.html#service
65
66use crate::shape_id::ShapeId;
67
68/// Models the [Smithy Service shape].
69///
70/// [Smithy Service shape]: https://smithy.io/2.0/spec/service-types.html#service
71pub trait ServiceShape {
72    /// The [`ShapeId`] of the service.
73    const ID: ShapeId;
74
75    /// The version of the service.
76    const VERSION: Option<&'static str>;
77
78    /// The [Protocol] applied to this service.
79    ///
80    /// [Protocol]: https://smithy.io/2.0/spec/protocol-traits.html
81    type Protocol;
82
83    /// An enumeration of all operations contained in this service.
84    type Operations;
85}
86
87pub trait ContainsOperation<Op>: ServiceShape {
88    const VALUE: Self::Operations;
89}