euan
euan
CDCloudflare Developers
Created by euan on 7/23/2024 in #🦀rust-on-workers
I tried this for the Rate Limiting API,
Amazing, thank you! I haven't fully validated it with an actual rate limit since I couldn't deploy it as-was, but that was the only issue rust-analyzer raised.
11 replies
CDCloudflare Developers
Created by euan on 7/23/2024 in #🦀rust-on-workers
I tried this for the Rate Limiting API,
@kflansburg Any word on making success a public field and this being merged?
11 replies
CDCloudflare Developers
Created by euan on 7/23/2024 in #🦀rust-on-workers
I tried this for the Rate Limiting API,
In context:
if ctx
.env
.get_binding::<RateLimiter>("RATE_LIMITER")?
.limit(api_key)
.await?
.success
{
return Response::error("Rate limit exceeded", 429);
}
if ctx
.env
.get_binding::<RateLimiter>("RATE_LIMITER")?
.limit(api_key)
.await?
.success
{
return Response::error("Rate limit exceeded", 429);
}
11 replies
CDCloudflare Developers
Created by euan on 7/23/2024 in #🦀rust-on-workers
I tried this for the Rate Limiting API,
Actually, had a quick install and test:
field success of RateLimitOutcome is private
11 replies
CDCloudflare Developers
Created by euan on 7/23/2024 in #🦀rust-on-workers
I tried this for the Rate Limiting API,
I should have time tomorrow, will give it a go and update .
11 replies
CDCloudflare Developers
Created by euan on 7/23/2024 in #🦀rust-on-workers
I tried this for the Rate Limiting API,
If anyone wants to grab my efforts as a starting block, feel free:
#[wasm_bindgen::prelude::wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends=js_sys::Object)]
#[derive(Clone, PartialEq, Eq)]
pub type RateLimiterSys;

#[wasm_bindgen(method, getter, js_name=limit)]
pub fn limit(this: &RateLimiterSys) -> String;
}
struct RateLimiter(RateLimiterSys);
impl EnvBinding for RateLimiter {
const TYPE_NAME: &'static str = "RateLimiter";
}
impl RateLimiter {
pub fn limit(&self) -> String {
self.0.limit()
}
}
#[wasm_bindgen::prelude::wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends=js_sys::Object)]
#[derive(Clone, PartialEq, Eq)]
pub type RateLimiterSys;

#[wasm_bindgen(method, getter, js_name=limit)]
pub fn limit(this: &RateLimiterSys) -> String;
}
struct RateLimiter(RateLimiterSys);
impl EnvBinding for RateLimiter {
const TYPE_NAME: &'static str = "RateLimiter";
}
impl RateLimiter {
pub fn limit(&self) -> String {
self.0.limit()
}
}
11 replies