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§
- Egress
- Egress connection wrapper use by client
- Extensions
- A type map of protocol extensions.
- Ingress
- Ingress connection wrapper use by servers
- Type
Erased Extension - A
TypeErasedExtensionis a type erased item which can be stored in anExtensions
Traits§
- DnsExtension
- DNS resolution related extensions.
- Extension
Extensionis type which can be stored inside anExtensionsstore- Extensions
Ref - GetMany
Arc - Helper trait powering
Extensions::get_many_arc; the owned-Arccounterpart ofGetManyRef. - GetMany
Ref - Helper trait powering
Extensions::get_many_ref: implemented for tuples ofExtensiontypes (up to arity 12). - 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. - From
Extensions - Derive a
from_extensionsconstructor that gathers extension pieces from arama_core::extensions::Extensionsstore in a single pass.