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

Publish on crates.io? #23

Closed
dpc opened this issue Jul 25, 2018 · 4 comments
Closed

Publish on crates.io? #23

dpc opened this issue Jul 25, 2018 · 4 comments

Comments

@dpc
Copy link

dpc commented Jul 25, 2018

Hi,

I would like to use this library in my project. Basically I want a coupled/embedded rate limiter via in memory Store.

But I can't find it on crates.io. Is there any reason for that?

@dpc dpc changed the title Publis on crates.io? Publish on crates.io? Jul 25, 2018
@dpc
Copy link
Author

dpc commented Jul 25, 2018

BTW. Is there any reason why RateLimiter doesn't just own Store? It's not convenient if it requires a mutable reference, forcing to use crates like rental and what not.

@brandur
Copy link
Owner

brandur commented Jul 31, 2018

But I can't find it on crates.io. Is there any reason for that?

Not really — I just figured that it was not all that useful as a crate.

I've just published it now though. We may as well have it up there.

BTW. Is there any reason why RateLimiter doesn't just own Store? It's not convenient if it requires a mutable reference, forcing to use crates like rental and what not.

If I understand the question correctly, it's so we can perform dependency injection. In tests, we can create a RateLimiter and inject a TestStore so that we don't need a real Redis dependency.

@dpc
Copy link
Author

dpc commented Jul 31, 2018

You can inject T: Store, and not have to deal with lifetimes and such: dpc/ratelimit-gcra@378d5e1

brandur added a commit that referenced this issue Jan 19, 2019
A nice trick that was suggested in [1] in which we remove the lifetime
(`'a`) from `RateLimiter` and instead give it just a basic `T:
store::Store`, and then enable a reference by implementing the `Store`
trait for `&'a mut T' where `T: Store`.

[1] #23
brandur added a commit that referenced this issue Jan 19, 2019
A nice trick that was suggested in [1] in which we remove the lifetime
(`'a`) from `RateLimiter` and instead give it just a basic `T:
store::Store`, and then enable a reference by implementing the `Store`
trait for `&'a mut T' where `T: Store`.

[1] #23
@brandur
Copy link
Owner

brandur commented Jan 19, 2019

@dpc Thanks for the tip! There was no reason for the previous way beyond that I didn't know this trick in Rust. I implemented something very similar to your change in #28.

@brandur brandur closed this as completed Jan 19, 2019
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