euan
euan
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);
}
5 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
5 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 .
5 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()
}
}
5 replies