tower_sessions_core/
extract.rs1use async_trait::async_trait;
2use axum_core::extract::FromRequestParts;
3use http::{request::Parts, StatusCode};
4
5use crate::session::Session;
6
7#[async_trait]
8impl<S> FromRequestParts<S> for Session
9where
10 S: Sync + Send,
11{
12 type Rejection = (http::StatusCode, &'static str);
13
14 async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
15 parts.extensions.get::<Session>().cloned().ok_or((
16 StatusCode::INTERNAL_SERVER_ERROR,
17 "Can't extract session. Is `SessionManagerLayer` enabled?",
18 ))
19 }
20}