Add axum-extra integration

This commit is contained in:
Diggory Blake 2023-08-14 12:31:02 +01:00
parent 7cd323a0fa
commit bf9ed6ae36
No known key found for this signature in database
GPG key ID: E6BDFA83146ABD40
2 changed files with 18 additions and 2 deletions

View file

@ -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")
}
}
}