mirror of
https://github.com/TECHNOFAB11/aerosol.git
synced 2025-12-11 23:50:07 +01:00
Add axum-extra integration
This commit is contained in:
parent
7cd323a0fa
commit
bf9ed6ae36
2 changed files with 18 additions and 2 deletions
|
|
@ -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" }
|
||||
|
|
|
|||
16
src/axum.rs
16
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<T: Resource>(pub T);
|
||||
|
||||
#[async_trait]
|
||||
impl<T: ConstructibleResource, S: Send + Sync> FromRequestParts<S> for Dep<T>
|
||||
impl<T: Resource, S: Send + Sync> FromRequestParts<S> for Dep<T>
|
||||
where
|
||||
Aero: FromRef<S>,
|
||||
{
|
||||
|
|
@ -103,3 +103,15 @@ impl<H: Resource, T: ResourceList> FromRef<Aero<HCons<H, T>>> for Aero {
|
|||
input.clone().into()
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "axum-extra")]
|
||||
mod extra_impls {
|
||||
use axum::extract::FromRef;
|
||||
|
||||
use crate::{Aero, ResourceList};
|
||||
|
||||
impl<R: ResourceList> FromRef<Aero<R>> for axum_extra::extract::cookie::Key {
|
||||
fn from_ref(input: &Aero<R>) -> Self {
|
||||
input.try_get().expect("Missing cookie key")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue