pub struct Key(/* private fields */);Expand description
An opaque identity a rate limit is tracked against.
A Key is whatever distinguishes one caller (or tenant, route, or resource)
from another: an IP address, a user id, an API token, an endpoint name. It is
stored as an owned byte string — inline for keys up to a couple dozen bytes,
on the heap beyond that — and two keys are equal exactly when their bytes are
equal, so the identity is the byte content, not the source type.
You rarely name Key directly. The check methods accept impl Into<Key>,
and this module provides From conversions for the common identity types, so
limiter.check("user:42") and limiter.check(ip) both work. Small keys are
stored inline, which is what keeps an existing-key check allocation-free.
§Examples
use rate_net::Key;
let a: Key = "tenant:acme".into();
let b: Key = String::from("tenant:acme").into();
assert_eq!(a, b);
assert_eq!(a.as_bytes(), b"tenant:acme");Implementations§
Trait Implementations§
impl Eq for Key
Auto Trait Implementations§
impl Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnsafeUnpin for Key
impl UnwindSafe for Key
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more