You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use async_trait::async_trait;use axum::{
extract::{FromRef,FromRequestParts},
http::request::Parts,};usecrate::{
error::ApiErrResp,
repositories::{user::User,DatabaseRepository},};pubstructAuthUser(User);pubstructDatabase<T:DatabaseRepository>{pubdb:T,}#[async_trait]impl<T:DatabaseRepository>FromRef<T>forDatabase<T>{fnfrom_ref(input:&T) -> Self{Database{db: input.from_reference(),}}}#[async_trait]impl<S>FromRequestParts<S>forAuthUserwhereS:Send + Sync,{typeRejection = ApiErrResp;asyncfnfrom_request_parts(parts:&mutParts,state:&S) -> Result<Self,Self::Rejection>{let db = Database::<S>::from_ref(state);unimplemented!()}}
as you can see from the above code DatabaseRepository is a custom trait How should I pass it to FromRequestParts implementation. I tried S: DatabaseRepository + Send + Sync.
1.
rustc: the trait bound `(): DatabaseRepository` is not satisfied
the trait `DatabaseRepository` is implemented for `SurrealDriver`
required for `AuthUser` to implement `FromRequest<(), axum_core::extract::private::ViaParts>` [E0277]
2.
rustc: the trait bound `(): DatabaseRepository` is not satisfied
the trait `DatabaseRepository` is implemented for `SurrealDriver`
required for `AuthUser` to implement `FromRequest<(), axum_core::extract::private::ViaParts>`
required for `fn(AuthUser) -> impl std::future::Future<Output = impl IntoResponse> {logout::logout}` to implement `Handler<(axum_core::extract::private::ViaParts, AuthUser), ()>` [E0277]
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Summary
as you can see from the above code
DatabaseRepository
is a custom trait How should I pass it to FromRequestParts implementation. I triedS: DatabaseRepository + Send + Sync
.Then I got the following error:
axum version
0.7.4
Beta Was this translation helpful? Give feedback.
All reactions