Skip to main content

Module extensions

Module extensions 

Expand description

Extensions passed to and between services

§State

rama supports two kinds of states:

  1. static state: this state can be a part of the service struct or captured by a closure
  2. dynamic state: these can be injected as Extensionss in Requests/Responses/Connections if it ExtensionsRef

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
InputExtensions
Wrapper type that can be inserted by leaf-like services when returning an output, to have the input extensions be accessible and preserved.
Stream
TypeErasedExtension
A TypeErasedExtension is a type erased item which can be stored in an Extensions

Traits§

ChainableExtensions
DnsExtension
DNS resolution related extensions.
Extension
Extension is type which can be stored inside an Extensions store
ExtensionsRef
GrpcExtension
gRPC related extensions.
HttpExtension
HTTP protocol related extensions.
NetExtension
Network and connection level extensions.
ProxyExtension
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::Extension for a type.