Module extensions
Expand description
Extensions passed to and between services
§State
rama supports two kinds of states:
- static state: this state can be a part of the service struct or captured by a closure
- dynamic state: these can be injected as
Extensionss in Requests/Responses/Connections if itExtensionsRef
Any state that is optional, and especially optional state injected by middleware, can be inserted using extensions.
It is however important to try as much as possible to then also consume this state in an approach that deals
gracefully with its absence. Good examples of this are header-related inputs. Headers might be set or not,
and so absence of Extensionss that might be created as a result of these might reasonably not exist.
It might of course still mean the app returns an error response when it is absent, but it should not unwrap/panic.
§Examples
§Example: Extensions
use rama_core::extensions::{Extensions, Extension};
#[derive(Debug, Clone, PartialEq)]
struct MyExt(i32);
impl Extension for MyExt {}
let mut ext = Extensions::default();
ext.insert(MyExt(5));
assert_eq!(ext.get_ref::<MyExt>(), Some(&MyExt(5)));Structs§
- Connection
- Egress
- Extensions
- A type map of protocol extensions.
- Ingress
- Input
- Input
Extensions - Wrapper type that can be inserted by leaf-like services when returning an output, to have the input extensions be accessible and preserved.
- Stream
- Type
Erased Extension - A
TypeErasedExtensionis a type erased item which can be stored in anExtensions
Traits§
- Chainable
Extensions - DnsExtension
- DNS resolution related extensions.
- Extension
Extensionis type which can be stored inside anExtensionsstore- Extensions
Ref - Grpc
Extension - gRPC related extensions.
- Http
Extension - HTTP protocol related extensions.
- NetExtension
- Network and connection level extensions.
- Proxy
Extension - Proxy related extensions.
- TlsExtension
- TLS and secure transport related extensions.
- UaExtension
- User-agent emulation related extensions.
- WsExtension
- WebSocket related extensions.
Derive Macros§
- Extension
- Derive an implementation of
rama_core::extensions::Extensionfor a type.