1 - | // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
|
2 - | /// The service builder for [`RestXmlExtras`].
|
3 - | ///
|
4 - | /// Constructed via [`RestXmlExtras::builder`].
|
5 - | pub struct RestXmlExtrasBuilder<Body, L, HttpPl, ModelPl> {
|
6 - | content_type_parameters: Option<::aws_smithy_http_server::routing::Route<Body>>,
|
7 - | layer: L,
|
8 - | http_plugin: HttpPl,
|
9 - | model_plugin: ModelPl,
|
10 - | }
|
11 - |
|
12 - | impl<Body, L, HttpPl, ModelPl> RestXmlExtrasBuilder<Body, L, HttpPl, ModelPl> {
|
13 - | /// Sets the [`ContentTypeParameters`](crate::operation_shape::ContentTypeParameters) operation.
|
14 - | ///
|
15 - | /// This should be an async function satisfying the [`Handler`](::aws_smithy_http_server::operation::Handler) trait.
|
16 - | /// See the [operation module documentation](::aws_smithy_http_server::operation) for more information.
|
17 - | ///
|
18 - | /// # Example
|
19 - | ///
|
20 - | /// ```no_run
|
21 - | /// use rest_xml_extras::{RestXmlExtras, RestXmlExtrasConfig};
|
22 - | ///
|
23 - | /// use rest_xml_extras::{input, output};
|
24 - | ///
|
25 - | /// async fn handler(input: input::ContentTypeParametersInput) -> output::ContentTypeParametersOutput {
|
26 - | /// todo!()
|
27 - | /// }
|
28 - | ///
|
29 - | /// let config = RestXmlExtrasConfig::builder().build();
|
30 - | /// let app = RestXmlExtras::builder(config)
|
31 - | /// .content_type_parameters(handler)
|
32 - | /// /* Set other handlers */
|
33 - | /// .build()
|
34 - | /// .unwrap();
|
35 - | /// # let app: RestXmlExtras<::aws_smithy_http_server::routing::RoutingService<::aws_smithy_http_server::protocol::rest::router::RestRouter<::aws_smithy_http_server::routing::Route>, ::aws_smithy_http_server::protocol::rest_xml::RestXml>> = app;
|
36 - | /// ```
|
37 - | ///
|
38 - | pub fn content_type_parameters<HandlerType, HandlerExtractors, UpgradeExtractors>(self, handler: HandlerType) -> Self
|
39 - | where
|
40 - | HandlerType: ::aws_smithy_http_server::operation::Handler<crate::operation_shape::ContentTypeParameters, HandlerExtractors>,
|
41 - |
|
42 - | ModelPl: ::aws_smithy_http_server::plugin::Plugin<
|
43 - | RestXmlExtras<L>,
|
44 - | crate::operation_shape::ContentTypeParameters,
|
45 - | ::aws_smithy_http_server::operation::IntoService<crate::operation_shape::ContentTypeParameters, HandlerType>
|
46 - | >,
|
47 - | ::aws_smithy_http_server::operation::UpgradePlugin::<UpgradeExtractors>: ::aws_smithy_http_server::plugin::Plugin<
|
48 - | RestXmlExtras<L>,
|
49 - | crate::operation_shape::ContentTypeParameters,
|
50 - | ModelPl::Output
|
51 - | >,
|
52 - | HttpPl: ::aws_smithy_http_server::plugin::Plugin<
|
53 - | RestXmlExtras<L>,
|
54 - | crate::operation_shape::ContentTypeParameters,
|
55 - | <
|
56 - | ::aws_smithy_http_server::operation::UpgradePlugin::<UpgradeExtractors>
|
57 - | as ::aws_smithy_http_server::plugin::Plugin<
|
58 - | RestXmlExtras<L>,
|
59 - | crate::operation_shape::ContentTypeParameters,
|
60 - | ModelPl::Output
|
61 - | >
|
62 - | >::Output
|
63 - | >,
|
64 - |
|
65 - | HttpPl::Output: ::tower::Service<::http::Request<Body>, Response = ::http::Response<::aws_smithy_http_server::body::BoxBody>, Error = ::std::convert::Infallible> + Clone + Send + 'static,
|
66 - | <HttpPl::Output as ::tower::Service<::http::Request<Body>>>::Future: Send + 'static,
|
67 - |
|
68 - | {
|
69 - | use ::aws_smithy_http_server::operation::OperationShapeExt;
|
70 - | use ::aws_smithy_http_server::plugin::Plugin;
|
71 - | let svc = crate::operation_shape::ContentTypeParameters::from_handler(handler);
|
72 - | let svc = self.model_plugin.apply(svc);
|
73 - | let svc = ::aws_smithy_http_server::operation::UpgradePlugin::<UpgradeExtractors>::new()
|
74 - | .apply(svc);
|
75 - | let svc = self.http_plugin.apply(svc);
|
76 - | self.content_type_parameters_custom(svc)
|
77 - | }
|
78 - |
|
79 - | /// Sets the [`ContentTypeParameters`](crate::operation_shape::ContentTypeParameters) operation.
|
80 - | ///
|
81 - | /// This should be an async function satisfying the [`Handler`](::aws_smithy_http_server::operation::Handler) trait.
|
82 - | /// See the [operation module documentation](::aws_smithy_http_server::operation) for more information.
|
83 - | ///
|
84 - | /// # Example
|
85 - | ///
|
86 - | /// ```no_run
|
87 - | /// use rest_xml_extras::{RestXmlExtras, RestXmlExtrasConfig};
|
88 - | ///
|
89 - | /// use rest_xml_extras::{input, output};
|
90 - | ///
|
91 - | /// async fn handler(input: input::ContentTypeParametersInput) -> Result<output::ContentTypeParametersOutput, std::convert::Infallible> {
|
92 - | /// todo!()
|
93 - | /// }
|
94 - | ///
|
95 - | /// let config = RestXmlExtrasConfig::builder().build();
|
96 - | /// let svc = ::tower::util::service_fn(handler);
|
97 - | /// let app = RestXmlExtras::builder(config)
|
98 - | /// .content_type_parameters_service(svc)
|
99 - | /// /* Set other handlers */
|
100 - | /// .build()
|
101 - | /// .unwrap();
|
102 - | /// # let app: RestXmlExtras<::aws_smithy_http_server::routing::RoutingService<::aws_smithy_http_server::protocol::rest::router::RestRouter<::aws_smithy_http_server::routing::Route>, ::aws_smithy_http_server::protocol::rest_xml::RestXml>> = app;
|
103 - | /// ```
|
104 - | ///
|
105 - | pub fn content_type_parameters_service<S, ServiceExtractors, UpgradeExtractors>(self, service: S) -> Self
|
106 - | where
|
107 - | S: ::aws_smithy_http_server::operation::OperationService<crate::operation_shape::ContentTypeParameters, ServiceExtractors>,
|
108 - |
|
109 - | ModelPl: ::aws_smithy_http_server::plugin::Plugin<
|
110 - | RestXmlExtras<L>,
|
111 - | crate::operation_shape::ContentTypeParameters,
|
112 - | ::aws_smithy_http_server::operation::Normalize<crate::operation_shape::ContentTypeParameters, S>
|
113 - | >,
|
114 - | ::aws_smithy_http_server::operation::UpgradePlugin::<UpgradeExtractors>: ::aws_smithy_http_server::plugin::Plugin<
|
115 - | RestXmlExtras<L>,
|
116 - | crate::operation_shape::ContentTypeParameters,
|
117 - | ModelPl::Output
|
118 - | >,
|
119 - | HttpPl: ::aws_smithy_http_server::plugin::Plugin<
|
120 - | RestXmlExtras<L>,
|
121 - | crate::operation_shape::ContentTypeParameters,
|
122 - | <
|
123 - | ::aws_smithy_http_server::operation::UpgradePlugin::<UpgradeExtractors>
|
124 - | as ::aws_smithy_http_server::plugin::Plugin<
|
125 - | RestXmlExtras<L>,
|
126 - | crate::operation_shape::ContentTypeParameters,
|
127 - | ModelPl::Output
|
128 - | >
|
129 - | >::Output
|
130 - | >,
|
131 - |
|
132 - | HttpPl::Output: ::tower::Service<::http::Request<Body>, Response = ::http::Response<::aws_smithy_http_server::body::BoxBody>, Error = ::std::convert::Infallible> + Clone + Send + 'static,
|
133 - | <HttpPl::Output as ::tower::Service<::http::Request<Body>>>::Future: Send + 'static,
|
134 - |
|
135 - | {
|
136 - | use ::aws_smithy_http_server::operation::OperationShapeExt;
|
137 - | use ::aws_smithy_http_server::plugin::Plugin;
|
138 - | let svc = crate::operation_shape::ContentTypeParameters::from_service(service);
|
139 - | let svc = self.model_plugin.apply(svc);
|
140 - | let svc = ::aws_smithy_http_server::operation::UpgradePlugin::<UpgradeExtractors>::new()
|
141 - | .apply(svc);
|
142 - | let svc = self.http_plugin.apply(svc);
|
143 - | self.content_type_parameters_custom(svc)
|
144 - | }
|
145 - |
|
146 - | /// Sets the [`ContentTypeParameters`](crate::operation_shape::ContentTypeParameters) to a custom [`Service`](tower::Service).
|
147 - | /// not constrained by the Smithy contract.
|
148 - | fn content_type_parameters_custom<S>(mut self, svc: S) -> Self
|
149 - | where
|
150 - | S: ::tower::Service<
|
151 - | ::http::Request<Body>,
|
152 - | Response = ::http::Response<::aws_smithy_http_server::body::BoxBody>,
|
153 - | Error = ::std::convert::Infallible,
|
154 - | > + Clone
|
155 - | + Send
|
156 - | + 'static,
|
157 - | S::Future: Send + 'static,
|
158 - | {
|
159 - | self.content_type_parameters = Some(::aws_smithy_http_server::routing::Route::new(svc));
|
160 - | self
|
161 - | }
|
162 - | }
|
163 - |
|
164 - | impl<Body, L, HttpPl, ModelPl> RestXmlExtrasBuilder<Body, L, HttpPl, ModelPl> {
|
165 - | /// Constructs a [`RestXmlExtras`] from the arguments provided to the builder.
|
166 - | ///
|
167 - | /// Forgetting to register a handler for one or more operations will result in an error.
|
168 - | ///
|
169 - | /// Check out [`RestXmlExtrasBuilder::build_unchecked`] if you'd prefer the service to return status code 500 when an
|
170 - | /// unspecified route is requested.
|
171 - | pub fn build(
|
172 - | self,
|
173 - | ) -> Result<
|
174 - | RestXmlExtras<
|
175 - | ::aws_smithy_http_server::routing::RoutingService<
|
176 - | ::aws_smithy_http_server::protocol::rest::router::RestRouter<L::Service>,
|
177 - | ::aws_smithy_http_server::protocol::rest_xml::RestXml,
|
178 - | >,
|
179 - | >,
|
180 - | MissingOperationsError,
|
181 - | >
|
182 - | where
|
183 - | L: ::tower::Layer<::aws_smithy_http_server::routing::Route<Body>>,
|
184 - | {
|
185 - | let router = {
|
186 - | use ::aws_smithy_http_server::operation::OperationShape;
|
187 - | let mut missing_operation_names = std::collections::HashMap::new();
|
188 - | if self.content_type_parameters.is_none() {
|
189 - | missing_operation_names.insert(
|
190 - | crate::operation_shape::ContentTypeParameters::ID,
|
191 - | ".content_type_parameters()",
|
192 - | );
|
193 - | }
|
194 - | if !missing_operation_names.is_empty() {
|
195 - | return Err(MissingOperationsError {
|
196 - | operation_names2setter_methods: missing_operation_names,
|
197 - | });
|
198 - | }
|
199 - | let unexpected_error_msg = "this should never panic since we are supposed to check beforehand that a handler has been registered for this operation; please file a bug report under https://github.com/smithy-lang/smithy-rs/issues";
|
200 - |
|
201 - | ::aws_smithy_http_server::protocol::rest::router::RestRouter::from_iter([(
|
202 - | request_specs::content_type_parameters(),
|
203 - | self.content_type_parameters.expect(unexpected_error_msg),
|
204 - | )])
|
205 - | };
|
206 - | let svc = ::aws_smithy_http_server::routing::RoutingService::new(router);
|
207 - | let svc = svc.map(|s| s.layer(self.layer));
|
208 - | Ok(RestXmlExtras { svc })
|
209 - | }
|
210 - |
|
211 - | /// Constructs a [`RestXmlExtras`] from the arguments provided to the builder.
|
212 - | /// Operations without a handler default to returning 500 Internal Server Error to the caller.
|
213 - | ///
|
214 - | /// Check out [`RestXmlExtrasBuilder::build`] if you'd prefer the builder to fail if one or more operations do
|
215 - | /// not have a registered handler.
|
216 - | pub fn build_unchecked(self) -> RestXmlExtras<L::Service>
|
217 - | where
|
218 - | Body: Send + 'static,
|
219 - | L: ::tower::Layer<
|
220 - | ::aws_smithy_http_server::routing::RoutingService<
|
221 - | ::aws_smithy_http_server::protocol::rest::router::RestRouter<
|
222 - | ::aws_smithy_http_server::routing::Route<Body>,
|
223 - | >,
|
224 - | ::aws_smithy_http_server::protocol::rest_xml::RestXml,
|
225 - | >,
|
226 - | >,
|
227 - | {
|
228 - | let router = ::aws_smithy_http_server::protocol::rest::router::RestRouter::from_iter([(
|
229 - | request_specs::content_type_parameters(),
|
230 - | self.content_type_parameters.unwrap_or_else(|| {
|
231 - | let svc = ::aws_smithy_http_server::operation::MissingFailure::<
|
232 - | ::aws_smithy_http_server::protocol::rest_xml::RestXml,
|
233 - | >::default();
|
234 - | ::aws_smithy_http_server::routing::Route::new(svc)
|
235 - | }),
|
236 - | )]);
|
237 - | let svc = self
|
238 - | .layer
|
239 - | .layer(::aws_smithy_http_server::routing::RoutingService::new(
|
240 - | router,
|
241 - | ));
|
242 - | RestXmlExtras { svc }
|
243 - | }
|
244 - | }
|
245 - |
|
246 - | /// The error encountered when calling the [`RestXmlExtrasBuilder::build`] method if one or more operation handlers are not
|
247 - | /// specified.
|
248 - | #[derive(Debug)]
|
249 - | pub struct MissingOperationsError {
|
250 - | operation_names2setter_methods:
|
251 - | std::collections::HashMap<::aws_smithy_http_server::shape_id::ShapeId, &'static str>,
|
252 - | }
|
253 - |
|
254 - | impl std::fmt::Display for MissingOperationsError {
|
255 - | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
256 - | write!(
|
257 - | f,
|
258 - | "You must specify a handler for all operations attached to `RestXmlExtras`.\n\
|
259 - | We are missing handlers for the following operations:\n",
|
260 - | )?;
|
261 - | for operation_name in self.operation_names2setter_methods.keys() {
|
262 - | writeln!(f, "- {}", operation_name.absolute())?;
|
263 - | }
|
264 - |
|
265 - | writeln!(f, "\nUse the dedicated methods on `RestXmlExtrasBuilder` to register the missing handlers:")?;
|
266 - | for setter_name in self.operation_names2setter_methods.values() {
|
267 - | writeln!(f, "- {}", setter_name)?;
|
268 - | }
|
269 - | Ok(())
|
270 - | }
|
271 - | }
|
272 - |
|
273 - | impl std::error::Error for MissingOperationsError {}
|
274 - |
|
275 - | mod request_specs {
|
276 - | pub(super) fn content_type_parameters(
|
277 - | ) -> ::aws_smithy_http_server::routing::request_spec::RequestSpec {
|
278 - | ::aws_smithy_http_server::routing::request_spec::RequestSpec::new(
|
279 - | ::http::Method::PUT,
|
280 - | ::aws_smithy_http_server::routing::request_spec::UriSpec::new(
|
281 - | ::aws_smithy_http_server::routing::request_spec::PathAndQuerySpec::new(
|
282 - | ::aws_smithy_http_server::routing::request_spec::PathSpec::from_vector_unchecked(vec![
|
283 - | ::aws_smithy_http_server::routing::request_spec::PathSegment::Literal(String::from("ContentTypeParameters")),
|
284 - | ]),
|
285 - | ::aws_smithy_http_server::routing::request_spec::QuerySpec::from_vector_unchecked(vec![
|
286 - | ])
|
287 - | )
|
288 - | ),
|
289 - | )
|
290 - | }
|
291 - | }
|
292 - |
|
293 - | /// A REST XML service that sends XML requests and responses.
|
294 - | ///
|
295 - | /// See the [root](crate) documentation for more information.
|
296 - | #[derive(Clone)]
|
297 - | pub struct RestXmlExtras<
|
298 - | S = ::aws_smithy_http_server::routing::RoutingService<
|
299 - | ::aws_smithy_http_server::protocol::rest::router::RestRouter<
|
300 - | ::aws_smithy_http_server::routing::Route<::aws_smithy_http_server::body::BoxBody>,
|
301 - | >,
|
302 - | ::aws_smithy_http_server::protocol::rest_xml::RestXml,
|
303 - | >,
|
304 - | > {
|
305 - | // This is the router wrapped by layers.
|
306 - | svc: S,
|
307 - | }
|
308 - |
|
309 - | impl RestXmlExtras<()> {
|
310 - | /// Constructs a builder for [`RestXmlExtras`].
|
311 - | /// You must specify a configuration object holding any plugins and layers that should be applied
|
312 - | /// to the operations in this service.
|
313 - | pub fn builder<
|
314 - | Body,
|
315 - | L,
|
316 - | HttpPl: ::aws_smithy_http_server::plugin::HttpMarker,
|
317 - | ModelPl: ::aws_smithy_http_server::plugin::ModelMarker,
|
318 - | >(
|
319 - | config: RestXmlExtrasConfig<L, HttpPl, ModelPl>,
|
320 - | ) -> RestXmlExtrasBuilder<Body, L, HttpPl, ModelPl> {
|
321 - | RestXmlExtrasBuilder {
|
322 - | content_type_parameters: None,
|
323 - | layer: config.layers,
|
324 - | http_plugin: config.http_plugins,
|
325 - | model_plugin: config.model_plugins,
|
326 - | }
|
327 - | }
|
328 - |
|
329 - | /// Constructs a builder for [`RestXmlExtras`].
|
330 - | /// You must specify what plugins should be applied to the operations in this service.
|
331 - | ///
|
332 - | /// Use [`RestXmlExtras::builder_without_plugins`] if you don't need to apply plugins.
|
333 - | ///
|
334 - | /// Check out [`HttpPlugins`](::aws_smithy_http_server::plugin::HttpPlugins) and
|
335 - | /// [`ModelPlugins`](::aws_smithy_http_server::plugin::ModelPlugins) if you need to apply
|
336 - | /// multiple plugins.
|
337 - | #[deprecated(
|
338 - | since = "0.57.0",
|
339 - | note = "please use the `builder` constructor and register plugins on the `RestXmlExtrasConfig` object instead; see https://github.com/smithy-lang/smithy-rs/discussions/3096"
|
340 - | )]
|
341 - | pub fn builder_with_plugins<
|
342 - | Body,
|
343 - | HttpPl: ::aws_smithy_http_server::plugin::HttpMarker,
|
344 - | ModelPl: ::aws_smithy_http_server::plugin::ModelMarker,
|
345 - | >(
|
346 - | http_plugin: HttpPl,
|
347 - | model_plugin: ModelPl,
|
348 - | ) -> RestXmlExtrasBuilder<Body, ::tower::layer::util::Identity, HttpPl, ModelPl> {
|
349 - | RestXmlExtrasBuilder {
|
350 - | content_type_parameters: None,
|
351 - | layer: ::tower::layer::util::Identity::new(),
|
352 - | http_plugin,
|
353 - | model_plugin,
|
354 - | }
|
355 - | }
|
356 - |
|
357 - | /// Constructs a builder for [`RestXmlExtras`].
|
358 - | ///
|
359 - | /// Use [`RestXmlExtras::builder_with_plugins`] if you need to specify plugins.
|
360 - | #[deprecated(
|
361 - | since = "0.57.0",
|
362 - | note = "please use the `builder` constructor instead; see https://github.com/smithy-lang/smithy-rs/discussions/3096"
|
363 - | )]
|
364 - | pub fn builder_without_plugins<Body>() -> RestXmlExtrasBuilder<
|
365 - | Body,
|
366 - | ::tower::layer::util::Identity,
|
367 - | ::aws_smithy_http_server::plugin::IdentityPlugin,
|
368 - | ::aws_smithy_http_server::plugin::IdentityPlugin,
|
369 - | > {
|
370 - | Self::builder_with_plugins(
|
371 - | ::aws_smithy_http_server::plugin::IdentityPlugin,
|
372 - | ::aws_smithy_http_server::plugin::IdentityPlugin,
|
373 - | )
|
374 - | }
|
375 - | }
|
376 - |
|
377 - | impl<S> RestXmlExtras<S> {
|
378 - | /// Converts [`RestXmlExtras`] into a [`MakeService`](tower::make::MakeService).
|
379 - | pub fn into_make_service(self) -> ::aws_smithy_http_server::routing::IntoMakeService<Self> {
|
380 - | ::aws_smithy_http_server::routing::IntoMakeService::new(self)
|
381 - | }
|
382 - |
|
383 - | /// Converts [`RestXmlExtras`] into a [`MakeService`](tower::make::MakeService) with [`ConnectInfo`](::aws_smithy_http_server::request::connect_info::ConnectInfo).
|
384 - | pub fn into_make_service_with_connect_info<C>(
|
385 - | self,
|
386 - | ) -> ::aws_smithy_http_server::routing::IntoMakeServiceWithConnectInfo<Self, C> {
|
387 - | ::aws_smithy_http_server::routing::IntoMakeServiceWithConnectInfo::new(self)
|
388 - | }
|
389 - | }
|
390 - |
|
391 - | impl<S>
|
392 - | RestXmlExtras<
|
393 - | ::aws_smithy_http_server::routing::RoutingService<
|
394 - | ::aws_smithy_http_server::protocol::rest::router::RestRouter<S>,
|
395 - | ::aws_smithy_http_server::protocol::rest_xml::RestXml,
|
396 - | >,
|
397 - | >
|
398 - | {
|
399 - | /// Applies a [`Layer`](::tower::Layer) uniformly to all routes.
|
400 - | #[deprecated(
|
401 - | since = "0.57.0",
|
402 - | note = "please add layers to the `RestXmlExtrasConfig` object instead; see https://github.com/smithy-lang/smithy-rs/discussions/3096"
|
403 - | )]
|
404 - | pub fn layer<L>(
|
405 - | self,
|
406 - | layer: &L,
|
407 - | ) -> RestXmlExtras<
|
408 - | ::aws_smithy_http_server::routing::RoutingService<
|
409 - | ::aws_smithy_http_server::protocol::rest::router::RestRouter<L::Service>,
|
410 - | ::aws_smithy_http_server::protocol::rest_xml::RestXml,
|
411 - | >,
|
412 - | >
|
413 - | where
|
414 - | L: ::tower::Layer<S>,
|
415 - | {
|
416 - | RestXmlExtras {
|
417 - | svc: self.svc.map(|s| s.layer(layer)),
|
418 - | }
|
419 - | }
|
420 - |
|
421 - | /// Applies [`Route::new`](::aws_smithy_http_server::routing::Route::new) to all routes.
|
422 - | ///
|
423 - | /// This has the effect of erasing all types accumulated via layers.
|
424 - | pub fn boxed<B>(
|
425 - | self,
|
426 - | ) -> RestXmlExtras<
|
427 - | ::aws_smithy_http_server::routing::RoutingService<
|
428 - | ::aws_smithy_http_server::protocol::rest::router::RestRouter<
|
429 - | ::aws_smithy_http_server::routing::Route<B>,
|
430 - | >,
|
431 - | ::aws_smithy_http_server::protocol::rest_xml::RestXml,
|
432 - | >,
|
433 - | >
|
434 - | where
|
435 - | S: ::tower::Service<
|
436 - | ::http::Request<B>,
|
437 - | Response = ::http::Response<::aws_smithy_http_server::body::BoxBody>,
|
438 - | Error = std::convert::Infallible,
|
439 - | >,
|
440 - | S: Clone + Send + 'static,
|
441 - | S::Future: Send + 'static,
|
442 - | {
|
443 - | self.layer(&::tower::layer::layer_fn(
|
444 - | ::aws_smithy_http_server::routing::Route::new,
|
445 - | ))
|
446 - | }
|
447 - | }
|
448 - |
|
449 - | impl<S, R> ::tower::Service<R> for RestXmlExtras<S>
|
450 - | where
|
451 - | S: ::tower::Service<R>,
|
452 - | {
|
453 - | type Response = S::Response;
|
454 - | type Error = S::Error;
|
455 - | type Future = S::Future;
|
456 - |
|
457 - | fn poll_ready(
|
458 - | &mut self,
|
459 - | cx: &mut std::task::Context,
|
460 - | ) -> std::task::Poll<Result<(), Self::Error>> {
|
461 - | self.svc.poll_ready(cx)
|
462 - | }
|
463 - |
|
464 - | fn call(&mut self, request: R) -> Self::Future {
|
465 - | self.svc.call(request)
|
466 - | }
|
467 - | }
|
468 - |
|
469 - | /// An enumeration of all [operations](https://smithy.io/2.0/spec/service-types.html#operation) in RestXmlExtras.
|
470 - | #[allow(clippy::enum_variant_names)]
|
471 - | #[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
472 - | pub enum Operation {
|
473 - | ContentTypeParameters,
|
474 - | }
|
475 - |
|
476 - | impl Operation {
|
477 - | /// Returns the [operations](https://smithy.io/2.0/spec/service-types.html#operation) [`ShapeId`](::aws_smithy_http_server::shape_id::ShapeId).
|
478 - | pub fn shape_id(&self) -> ::aws_smithy_http_server::shape_id::ShapeId {
|
479 - | match self {
|
480 - | Operation::ContentTypeParameters => ::aws_smithy_http_server::shape_id::ShapeId::new(
|
481 - | "aws.protocoltests.restxml#ContentTypeParameters",
|
482 - | "aws.protocoltests.restxml",
|
483 - | "ContentTypeParameters",
|
484 - | ),
|
485 - | }
|
486 - | }
|
487 - | }
|
488 - | impl<L>
|
489 - | ::aws_smithy_http_server::service::ContainsOperation<
|
490 - | crate::operation_shape::ContentTypeParameters,
|
491 - | > for RestXmlExtras<L>
|
492 - | {
|
493 - | const VALUE: Operation = Operation::ContentTypeParameters;
|
494 - | }
|
495 - |
|
496 - | impl<S> ::aws_smithy_http_server::service::ServiceShape for RestXmlExtras<S> {
|
497 - | const ID: ::aws_smithy_http_server::shape_id::ShapeId =
|
498 - | ::aws_smithy_http_server::shape_id::ShapeId::new(
|
499 - | "aws.protocoltests.restxml#RestXmlExtras",
|
500 - | "aws.protocoltests.restxml",
|
501 - | "RestXmlExtras",
|
502 - | );
|
503 - |
|
504 - | const VERSION: Option<&'static str> = Some("2024-04-15");
|
505 - |
|
506 - | type Protocol = ::aws_smithy_http_server::protocol::rest_xml::RestXml;
|
507 - |
|
508 - | type Operations = Operation;
|
509 - | }
|
510 - | /// Configuration for the [`RestXmlExtras`]. This is the central place where to register and
|
511 - | /// configure [`::tower::Layer`]s, HTTP plugins, and model plugins.
|
512 - | ///
|
513 - | /// ```rust,no_run
|
514 - | /// # use rest_xml_extras::RestXmlExtrasConfig;
|
515 - | /// # use ::aws_smithy_http_server::plugin::IdentityPlugin;
|
516 - | /// # use ::tower::layer::util::Identity;
|
517 - | /// # let authentication_plugin = IdentityPlugin;
|
518 - | /// # let authorization_plugin = IdentityPlugin;
|
519 - | /// # let server_request_id_provider_layer = Identity::new();
|
520 - | /// let config = RestXmlExtrasConfig::builder()
|
521 - | /// // Layers get executed first...
|
522 - | /// .layer(server_request_id_provider_layer)
|
523 - | /// // ...then HTTP plugins...
|
524 - | /// .http_plugin(authentication_plugin)
|
525 - | /// // ...and right after deserialization, model plugins.
|
526 - | /// .model_plugin(authorization_plugin)
|
527 - | /// .build();
|
528 - | /// ```
|
529 - | ///
|
530 - | /// See the [`plugin`] system for details.
|
531 - | ///
|
532 - | /// [`plugin`]: ::aws_smithy_http_server::plugin
|
533 - | #[derive(::std::fmt::Debug)]
|
534 - | pub struct RestXmlExtrasConfig<L, H, M> {
|
535 - | layers: L,
|
536 - | http_plugins: H,
|
537 - | model_plugins: M,
|
538 - | }
|
539 - |
|
540 - | impl RestXmlExtrasConfig<(), (), ()> {
|
541 - | /// Returns a builder to construct the configuration.
|
542 - | pub fn builder() -> RestXmlExtrasConfigBuilder<
|
543 - | ::tower::layer::util::Identity,
|
544 - | ::aws_smithy_http_server::plugin::IdentityPlugin,
|
545 - | ::aws_smithy_http_server::plugin::IdentityPlugin,
|
546 - | > {
|
547 - | RestXmlExtrasConfigBuilder {
|
548 - | layers: ::tower::layer::util::Identity::new(),
|
549 - | http_plugins: ::aws_smithy_http_server::plugin::IdentityPlugin,
|
550 - | model_plugins: ::aws_smithy_http_server::plugin::IdentityPlugin,
|
551 - | }
|
552 - | }
|
553 - | }
|
554 - |
|
555 - | /// Builder returned by [`RestXmlExtrasConfig::builder()`].
|
556 - | #[derive(::std::fmt::Debug)]
|
557 - | pub struct RestXmlExtrasConfigBuilder<L, H, M> {
|
558 - | pub(crate) layers: L,
|
559 - | pub(crate) http_plugins: H,
|
560 - | pub(crate) model_plugins: M,
|
561 - | }
|
562 - |
|
563 - | impl<L, H, M> RestXmlExtrasConfigBuilder<L, H, M> {
|
564 - | /// Add a [`::tower::Layer`] to the service.
|
565 - | pub fn layer<NewLayer>(
|
566 - | self,
|
567 - | layer: NewLayer,
|
568 - | ) -> RestXmlExtrasConfigBuilder<::tower::layer::util::Stack<NewLayer, L>, H, M> {
|
569 - | RestXmlExtrasConfigBuilder {
|
570 - | layers: ::tower::layer::util::Stack::new(layer, self.layers),
|
571 - | http_plugins: self.http_plugins,
|
572 - | model_plugins: self.model_plugins,
|
573 - | }
|
574 - | }
|
575 - |
|
576 - | /// Add a HTTP [plugin] to the service.
|
577 - | ///
|
578 - | /// [plugin]: ::aws_smithy_http_server::plugin
|
579 - | // We eagerly require `NewPlugin: HttpMarker`, despite not really needing it, because compiler
|
580 - | // errors get _substantially_ better if the user makes a mistake.
|
581 - | pub fn http_plugin<NewPlugin: ::aws_smithy_http_server::plugin::HttpMarker>(
|
582 - | self,
|
583 - | http_plugin: NewPlugin,
|
584 - | ) -> RestXmlExtrasConfigBuilder<L, ::aws_smithy_http_server::plugin::PluginStack<NewPlugin, H>, M>
|
585 - | {
|
586 - | RestXmlExtrasConfigBuilder {
|
587 - | layers: self.layers,
|
588 - | http_plugins: ::aws_smithy_http_server::plugin::PluginStack::new(
|
589 - | http_plugin,
|
590 - | self.http_plugins,
|
591 - | ),
|
592 - | model_plugins: self.model_plugins,
|
593 - | }
|
594 - | }
|
595 - |
|
596 - | /// Add a model [plugin] to the service.
|
597 - | ///
|
598 - | /// [plugin]: ::aws_smithy_http_server::plugin
|
599 - | // We eagerly require `NewPlugin: ModelMarker`, despite not really needing it, because compiler
|
600 - | // errors get _substantially_ better if the user makes a mistake.
|
601 - | pub fn model_plugin<NewPlugin: ::aws_smithy_http_server::plugin::ModelMarker>(
|
602 - | self,
|
603 - | model_plugin: NewPlugin,
|
604 - | ) -> RestXmlExtrasConfigBuilder<L, H, ::aws_smithy_http_server::plugin::PluginStack<NewPlugin, M>>
|
605 - | {
|
606 - | RestXmlExtrasConfigBuilder {
|
607 - | layers: self.layers,
|
608 - | http_plugins: self.http_plugins,
|
609 - | model_plugins: ::aws_smithy_http_server::plugin::PluginStack::new(
|
610 - | model_plugin,
|
611 - | self.model_plugins,
|
612 - | ),
|
613 - | }
|
614 - | }
|
615 - |
|
616 - | /// Build the configuration.
|
617 - | pub fn build(self) -> super::RestXmlExtrasConfig<L, H, M> {
|
618 - | super::RestXmlExtrasConfig {
|
619 - | layers: self.layers,
|
620 - | http_plugins: self.http_plugins,
|
621 - | model_plugins: self.model_plugins,
|
622 - | }
|
623 - | }
|
624 - | }
|
625 - | /// A macro to help with scoping [plugins](::aws_smithy_http_server::plugin) to a subset of all operations.
|
626 - | ///
|
627 - | /// In contrast to [`aws_smithy_http_server::scope`](::aws_smithy_http_server::scope), this macro has knowledge
|
628 - | /// of the service and any operations _not_ specified will be placed in the opposing group.
|
629 - | ///
|
630 - | /// # Example
|
631 - | ///
|
632 - | /// ```rust
|
633 - | /// scope! {
|
634 - | /// /// Includes [`ContentTypeParameters`], excluding all other operations.
|
635 - | /// struct ScopeA {
|
636 - | /// includes: [ContentTypeParameters]
|
637 - | /// }
|
638 - | /// }
|
639 - | ///
|
640 - | /// scope! {
|
641 - | /// /// Excludes [`ContentTypeParameters`], excluding all other operations.
|
642 - | /// struct ScopeB {
|
643 - | /// excludes: [ContentTypeParameters]
|
644 - | /// }
|
645 - | /// }
|
646 - | ///
|
647 - | /// # use ::aws_smithy_http_server::plugin::{Plugin, Scoped};
|
648 - | /// # use rest_xml_extras::scope;
|
649 - | /// # struct MockPlugin;
|
650 - | /// # impl<S, Op, T> Plugin<S, Op, T> for MockPlugin { type Output = u32; fn apply(&self, input: T) -> u32 { 3 } }
|
651 - | /// # let scoped_a = Scoped::new::<ScopeA>(MockPlugin);
|
652 - | /// # let scoped_b = Scoped::new::<ScopeB>(MockPlugin);
|
653 - | /// # let a = Plugin::<(), rest_xml_extras::operation_shape::ContentTypeParameters, u64>::apply(&scoped_a, 6);
|
654 - | /// # let b = Plugin::<(), rest_xml_extras::operation_shape::ContentTypeParameters, u64>::apply(&scoped_b, 6);
|
655 - | /// # assert_eq!(a, 3_u32);
|
656 - | /// # assert_eq!(b, 6_u64);
|
657 - | /// ```
|
658 - | #[macro_export]
|
659 - | macro_rules! scope {
|
660 - | // Completed, render impls
|
661 - | (@ $ name: ident, $ contains: ident () ($($ temp: ident)*) ($($ not_member: ident)*)) => {
|
662 - | $(
|
663 - | impl ::aws_smithy_http_server::plugin::scoped::Membership<$ temp> for $ name {
|
664 - | type Contains = ::aws_smithy_http_server::plugin::scoped::$ contains;
|
665 - | }
|
666 - | )*
|
667 - | $(
|
668 - | impl ::aws_smithy_http_server::plugin::scoped::Membership<$ not_member> for $ name {
|
669 - | type Contains = ::aws_smithy_http_server::plugin::scoped::$ contains;
|
670 - | }
|
671 - | )*
|
672 - | };
|
673 - | // All `not_member`s exhausted, move `temp` into `not_member`
|
674 - | (@ $ name: ident, $ contains: ident ($($ member: ident)*) ($($ temp: ident)*) ()) => {
|
675 - | scope! { @ $ name, $ contains ($($ member)*) () ($($ temp)*) }
|
676 - | };
|
677 - |
|
678 - | // ContentTypeParameters match found, pop from both `member` and `not_member`
|
679 - | (@ $ name: ident, $ contains: ident (ContentTypeParameters $($ member: ident)*) ($($ temp: ident)*) (ContentTypeParameters $($ not_member: ident)*)) => {
|
680 - | scope! { @ $ name, $ contains ($($ member)*) ($($ temp)*) ($($ not_member)*) }
|
681 - | };
|
682 - | // ContentTypeParameters match not found, pop from `not_member` into `temp` stack
|
683 - | (@ $ name: ident, $ contains: ident (ContentTypeParameters $($ member: ident)*) ($($ temp: ident)*) ($ other: ident $($ not_member: ident)*)) => {
|
684 - | scope! { @ $ name, $ contains (ContentTypeParameters $($ member)*) ($ other $($ temp)*) ($($ not_member)*) }
|
685 - | };
|
686 - |
|
687 - | (
|
688 - | $(#[$ attrs:meta])*
|
689 - | $ vis:vis struct $ name:ident {
|
690 - | includes: [$($ include:ident),*]
|
691 - | }
|
692 - | ) => {
|
693 - | use $ crate::operation_shape::*;
|
694 - | ::aws_smithy_http_server::scope! {
|
695 - | $(#[$ attrs])*
|
696 - | $ vis struct $ name {
|
697 - | includes: [$($ include),*],
|
698 - | excludes: []
|
699 - | }
|
700 - | }
|
701 - | scope! { @ $ name, False ($($ include)*) () (ContentTypeParameters) }
|
702 - | };
|
703 - | (
|
704 - | $(#[$ attrs:meta])*
|
705 - | $ vis:vis struct $ name:ident {
|
706 - | excludes: [$($ exclude:ident),*]
|
707 - | }
|
708 - | ) => {
|
709 - | use $ crate::operation_shape::*;
|
710 - |
|
711 - | ::aws_smithy_http_server::scope! {
|
712 - | $(#[$ attrs])*
|
713 - | $ vis struct $ name {
|
714 - | includes: [],
|
715 - | excludes: [$($ exclude),*]
|
716 - | }
|
717 - | }
|
718 - | scope! { @ $ name, True ($($ exclude)*) () (ContentTypeParameters) }
|
719 - | };
|
720 - | }
|