diff --git a/Cargo.toml b/Cargo.toml index ab0b01c..5cb5e5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,12 +14,16 @@ all-features = true default = [] async = ["async-trait"] axum = ["dep:axum", "async", "tracing", "thiserror"] +axum-extra = ["axum", "dep:axum-extra"] [dependencies] parking_lot = "0.12.1" anymap = { version = "1.0.0-beta.2", features = ["hashbrown"] } async-trait = { version = "0.1", optional = true } axum = { version = "0.6", optional = true } +axum-extra = { version = "0.7.7", optional = true, features = [ + "cookie-private", +] } tracing = { version = "0.1", optional = true } thiserror = { version = "1.0", optional = true } anyhow = { version = "1.0" } diff --git a/src/axum.rs b/src/axum.rs index 0cbda29..228db42 100644 --- a/src/axum.rs +++ b/src/axum.rs @@ -16,7 +16,7 @@ use axum::{ }; use frunk::HCons; -use crate::{Aero, AsyncConstructibleResource, ConstructibleResource, Resource, ResourceList}; +use crate::{Aero, AsyncConstructibleResource, Resource, ResourceList}; /// Type of axum Rejection returned when a resource cannot be acquired #[derive(Debug, thiserror::Error)] @@ -64,7 +64,7 @@ impl DependencyError { pub struct Dep(pub T); #[async_trait] -impl FromRequestParts for Dep +impl FromRequestParts for Dep where Aero: FromRef, { @@ -103,3 +103,15 @@ impl FromRef>> for Aero { input.clone().into() } } +#[cfg(feature = "axum-extra")] +mod extra_impls { + use axum::extract::FromRef; + + use crate::{Aero, ResourceList}; + + impl FromRef> for axum_extra::extract::cookie::Key { + fn from_ref(input: &Aero) -> Self { + input.try_get().expect("Missing cookie key") + } + } +}