pub struct SessionInjection { /* private fields */ }Expand description
Write-only mechanism for middleware to populate session state
Prevents middleware from interfering with core session management while allowing controlled injection of custom state and metadata.
§Design
- Write-only: Middleware cannot read existing session state
- Deferred application: Changes applied after all middleware succeed
- Isolation: Each middleware’s changes are independent
§Examples
use turul_http_mcp_server::middleware::SessionInjection;
use serde_json::json;
let mut injection = SessionInjection::new();
// Set typed state
injection.set_state("user_id", json!(12345));
injection.set_state("role", json!("admin"));
// Set metadata
injection.set_metadata("authenticated_at", json!("2025-10-04T12:00:00Z"));
// State and metadata are applied to session after middleware succeeds
assert!(!injection.is_empty());Implementations§
Source§impl SessionInjection
impl SessionInjection
Sourcepub fn new() -> SessionInjection
pub fn new() -> SessionInjection
Create a new empty session injection
Sourcepub fn set_state(&mut self, key: impl Into<String>, value: Value)
pub fn set_state(&mut self, key: impl Into<String>, value: Value)
Set a state entry
§Parameters
key: State key (used withSessionContext::get_typed_state())value: JSON value to store
Sourcepub fn set_metadata(&mut self, key: impl Into<String>, value: Value)
pub fn set_metadata(&mut self, key: impl Into<String>, value: Value)
Trait Implementations§
Source§impl Clone for SessionInjection
impl Clone for SessionInjection
Source§fn clone(&self) -> SessionInjection
fn clone(&self) -> SessionInjection
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SessionInjection
impl Debug for SessionInjection
Source§impl Default for SessionInjection
impl Default for SessionInjection
Source§fn default() -> SessionInjection
fn default() -> SessionInjection
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SessionInjection
impl RefUnwindSafe for SessionInjection
impl Send for SessionInjection
impl Sync for SessionInjection
impl Unpin for SessionInjection
impl UnwindSafe for SessionInjection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.