-
Is there some way to create an extractor which would take additional parameters? What I had in mind is some kind of extractor to get a user only if it has a certain role assigned, something like this: fn some_handler(RequireRole(admin): RequireRole(Role::Admin)) -> IntoResponse {
...
} where the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This is possible on Nightly where you can declare a const-generic On stable, you can declare a |
Beta Was this translation helpful? Give feedback.
This is possible on Nightly where you can declare a const-generic
RequireRole<const R: Role>
with the right unstable feature (I don't know the name off the top of my head but the compiler error message should mention it). It would then be used asRequireRole(admin): RequireRole<Role::Admin>
.On stable, you can declare a
RequireRole<R: Role>
withAdmin
being one of several zero-sized types that implement theRole
trait. However, in that case you need to add aPhantomData
field toRequireRole
and so the pattern match will have to beRequireRole(admin, _): RequireRole<Admin>
if you still want to use destructuring.