cloudflare / cloudflare/workers-rs
[BUG] Binding cannot be cast to the type RateLimiter from Ratelimit
- Dominant language
- Rust
- Stars
- 3.7k
- Forks
- 429
- Avg merge
- 20h 28m
- Merged PRs (30d)
- 7
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### What version of `workers-rs` are you using?
0.5.0
### What version of `wrangler` are you using?
3.106.0
### Describe the bug
When trying to retrieve a `RateLimiter` with `Env::get_binding` the following error occurs:
```
Binding cannot be cast to the type RateLimiter from Ratelimit
```
### Steps To Reproduce
I have the following in my `wrangler.toml`:
```toml
[[unsafe.bindings]]
name = "MY_RATE_LIMITER"
type = "ratelimit"
namespace_id = "1001"
simple = { limit = 10, period = 60}
```
And the rate limiter is being retrieved like so:
```rs
// ...
let rate_limiter = cx
.env
.get_binding::("MY_RATE_LIMITER")?;
let rate_limit_outcome = rate_limiter
.limit(format!("user_id:{}", claims.user_id))
.await?;
if !rate_limit_outcome.success {
return Response::error(
"Rate limit exceeded.",
StatusCode::TOO_MANY_REQUESTS.as_u16(),
);
}
```
Related GitHub Discussion: https://github.com/cloudflare/workers-rs/discussions/692
Contributor guide
Assessment
This issue has not been assessed yet.