Function aws_smithy_http_server::plugin::plugin_from_operation_fn
source · pub fn plugin_from_operation_fn<F>(f: F) -> OperationFn<F>
Expand description
Constructs a Plugin
using a closure over the [ServiceShape::]
F: Fn(ShapeId, T) -> Service`.
§Example
use aws_smithy_http_server::plugin::plugin_from_operation_fn;
use tower::layer::layer_fn;
struct FooService<S> {
info: String,
inner: S
}
fn map<S>(op: Operation, inner: S) -> FooService<S> {
match op {
Operation::CheckHealth => FooService { info: op.shape_id().name().to_string(), inner },
Operation::GetPokemonSpecies => FooService { info: "bar".to_string(), inner },
_ => todo!()
}
}
// This plugin applies the `FooService` middleware around every operation.
let plugin = plugin_from_operation_fn(map);