mirror of
https://github.com/TECHNOFAB11/aerosol.git
synced 2026-02-02 01:15:12 +01:00
Add axum-extra integration
This commit is contained in:
parent
7cd323a0fa
commit
bf9ed6ae36
2 changed files with 18 additions and 2 deletions
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