Skip to content

Custom parametrized extractor #1533

Answered by jplatte
czocher asked this question in Q&A
Nov 16, 2022 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

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 as RequireRole(admin): RequireRole<Role::Admin>.

On stable, you can declare a RequireRole<R: Role> with Admin being one of several zero-sized types that implement the Role trait. However, in that case you need to add a PhantomData field to RequireRole and so the pattern match will have to be RequireRole(admin, _): RequireRole<Admin> if you still want to use destructuring.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@czocher
Comment options

@jplatte
Comment options

Answer selected by czocher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants