Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyExtractor generic parameter makes conditional runtime handling difficult #31

Open
dpc opened this issue Jun 8, 2024 · 3 comments
Open

Comments

@dpc
Copy link
Contributor

dpc commented Jun 8, 2024

In my app I'd like the user to have an option to rate-limit based on IP (if running in a standalone mode), or reverse proxy headers. However currently conditionally setting the extractor makes the types be incompatible.

Seems to me like either GovernorConfig should drop the K generic and Box key_extractor to Box<dyn KeyExtractor>, or at very least impl KeyExtractor for Box<T> where T: KeyExtractor (and maybe for Arc<T> too), to allow people to have unified GovernorConfig<Box<dyn KeyExtractor>> that can have runtime-conditional key extractor.

@dpc
Copy link
Contributor Author

dpc commented Jun 9, 2024

Oh, I tried to impl Arc<dyn KeyExtractor> via newtype, and it doesn't work because : Clone, preventing it from being object safe.

@benwis
Copy link
Owner

benwis commented Jun 11, 2024

Hmm, if my understanding of Arc and dyn is correct, that thing should be object safe, and Clone. Can you provide a minimal example? I'm also wondering if you've tried impl KeyExtractor.

@dpc
Copy link
Contributor Author

dpc commented Jun 12, 2024

: Clone implies : Sized which prevent the trait for being usable as dyn KeyExtractor.

BTW. I have worked it around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants