pub struct Bucket { /* private fields */ }Expand description
This is the main struct to do everything you need
§Global or task-based
Essentially buckets just store usages and limits, meaning you can create a different bucket for each kind of limit: each of your commands, separate buckets for channel and user usage if you want to have different limits for each etc.
§Usage
Register usages using the Bucket::register method after getting the
limit with Bucket::limit_duration
IDs use NonZeroU64 to be compatible with any
kind of ID: users, guilds or even your custom IDs
Implementations§
Source§impl Bucket
impl Bucket
Sourcepub fn limit_duration(&self, id: u64) -> Option<Duration>
pub fn limit_duration(&self, id: u64) -> Option<Duration>
Get the duration to wait until the next usage by id, returns None
if the id isn’t limited, you should call this before registering a
usage
if let Some(duration) = bucket.limit_duration(user_id) {
tokio::time::sleep(duration).await;
}
bucket.register(user_id);§Panics
If the id is 0
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Bucket
impl !RefUnwindSafe for Bucket
impl Send for Bucket
impl Sync for Bucket
impl Unpin for Bucket
impl UnwindSafe for Bucket
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