[−]Struct serenity::CACHE
A mutable and lazily-initialized static binding. It can be accessed across any function and in any context.
This Cache
instance is updated for every event received, so you do
not need to maintain your own cache.
See the cache module documentation for more details.
The Cache itself is wrapped within an RwLock
, which allows for
multiple readers or at most one writer at a time across threads. This
means that you may have multiple commands reading from the Cache
concurrently.
Examples
Retrieve the current user's Id, by opening a Read guard:
use serenity::CACHE; println!("{}", CACHE.read().user.id);
Update the cache's settings to enable caching of channels' messages:
use serenity::CACHE; // Cache up to the 10 most recent messages per channel. CACHE.write().settings_mut().max_messages(10);
Methods from Deref<Target = RwLock<Cache>>
pub fn read(&self) -> RwLockReadGuard<T>
[src]
pub fn read(&self) -> RwLockReadGuard<T>
Locks this rwlock with shared read access, blocking the current thread until it can be acquired.
The calling thread will be blocked until there are no more writers which hold the lock. There may be other readers currently inside the lock when this method returns.
Note that attempts to recursively acquire a read lock on a RwLock
when
the current thread already holds one may result in a deadlock.
Returns an RAII guard which will release this thread's shared access once it is dropped.
pub fn try_read(&self) -> Option<RwLockReadGuard<T>>
[src]
pub fn try_read(&self) -> Option<RwLockReadGuard<T>>
Attempts to acquire this rwlock with shared read access.
If the access could not be granted at this time, then None
is returned.
Otherwise, an RAII guard is returned which will release the shared access
when it is dropped.
This function does not block.
pub fn try_read_for(&self, timeout: Duration) -> Option<RwLockReadGuard<T>>
[src]
pub fn try_read_for(&self, timeout: Duration) -> Option<RwLockReadGuard<T>>
Attempts to acquire this rwlock with shared read access until a timeout is reached.
If the access could not be granted before the timeout expires, then
None
is returned. Otherwise, an RAII guard is returned which will
release the shared access when it is dropped.
pub fn try_read_until(&self, timeout: Instant) -> Option<RwLockReadGuard<T>>
[src]
pub fn try_read_until(&self, timeout: Instant) -> Option<RwLockReadGuard<T>>
Attempts to acquire this rwlock with shared read access until a timeout is reached.
If the access could not be granted before the timeout expires, then
None
is returned. Otherwise, an RAII guard is returned which will
release the shared access when it is dropped.
pub fn read_recursive(&self) -> RwLockReadGuard<T>
[src]
pub fn read_recursive(&self) -> RwLockReadGuard<T>
Locks this rwlock with shared read access, blocking the current thread until it can be acquired.
The calling thread will be blocked until there are no more writers which hold the lock. There may be other readers currently inside the lock when this method returns.
Unlike read
, this method is guaranteed to succeed without blocking if
another read lock is held at the time of the call. This allows a thread
to recursively lock a RwLock
. However using this method can cause
writers to starve since readers no longer block if a writer is waiting
for the lock.
Returns an RAII guard which will release this thread's shared access once it is dropped.
pub fn try_read_recursive(&self) -> Option<RwLockReadGuard<T>>
[src]
pub fn try_read_recursive(&self) -> Option<RwLockReadGuard<T>>
Attempts to acquire this rwlock with shared read access.
If the access could not be granted at this time, then None
is returned.
Otherwise, an RAII guard is returned which will release the shared access
when it is dropped.
This method is guaranteed to succeed if another read lock is held at the
time of the call. See the documentation for read_recursive
for details.
This function does not block.
pub fn try_read_recursive_for(
&self,
timeout: Duration
) -> Option<RwLockReadGuard<T>>
[src]
pub fn try_read_recursive_for(
&self,
timeout: Duration
) -> Option<RwLockReadGuard<T>>
Attempts to acquire this rwlock with shared read access until a timeout is reached.
If the access could not be granted before the timeout expires, then
None
is returned. Otherwise, an RAII guard is returned which will
release the shared access when it is dropped.
This method is guaranteed to succeed without blocking if another read
lock is held at the time of the call. See the documentation for
read_recursive
for details.
pub fn try_read_recursive_until(
&self,
timeout: Instant
) -> Option<RwLockReadGuard<T>>
[src]
pub fn try_read_recursive_until(
&self,
timeout: Instant
) -> Option<RwLockReadGuard<T>>
Attempts to acquire this rwlock with shared read access until a timeout is reached.
If the access could not be granted before the timeout expires, then
None
is returned. Otherwise, an RAII guard is returned which will
release the shared access when it is dropped.
pub fn write(&self) -> RwLockWriteGuard<T>
[src]
pub fn write(&self) -> RwLockWriteGuard<T>
Locks this rwlock with exclusive write access, blocking the current thread until it can be acquired.
This function will not return while other writers or other readers currently have access to the lock.
Returns an RAII guard which will drop the write access of this rwlock when dropped.
pub fn try_write(&self) -> Option<RwLockWriteGuard<T>>
[src]
pub fn try_write(&self) -> Option<RwLockWriteGuard<T>>
Attempts to lock this rwlock with exclusive write access.
If the lock could not be acquired at this time, then None
is returned.
Otherwise, an RAII guard is returned which will release the lock when
it is dropped.
This function does not block.
pub fn try_write_for(&self, timeout: Duration) -> Option<RwLockWriteGuard<T>>
[src]
pub fn try_write_for(&self, timeout: Duration) -> Option<RwLockWriteGuard<T>>
Attempts to acquire this rwlock with exclusive write access until a timeout is reached.
If the access could not be granted before the timeout expires, then
None
is returned. Otherwise, an RAII guard is returned which will
release the exclusive access when it is dropped.
pub fn try_write_until(&self, timeout: Instant) -> Option<RwLockWriteGuard<T>>
[src]
pub fn try_write_until(&self, timeout: Instant) -> Option<RwLockWriteGuard<T>>
Attempts to acquire this rwlock with exclusive write access until a timeout is reached.
If the access could not be granted before the timeout expires, then
None
is returned. Otherwise, an RAII guard is returned which will
release the exclusive access when it is dropped.
pub fn upgradable_read(&self) -> RwLockUpgradableReadGuard<T>
[src]
pub fn upgradable_read(&self) -> RwLockUpgradableReadGuard<T>
Locks this rwlock with upgradable read access, blocking the current thread until it can be acquired.
The calling thread will be blocked until there are no more writers or other upgradable reads which hold the lock. There may be other readers currently inside the lock when this method returns.
Returns an RAII guard which will release this thread's shared access once it is dropped.
pub fn try_upgradable_read(&self) -> Option<RwLockUpgradableReadGuard<T>>
[src]
pub fn try_upgradable_read(&self) -> Option<RwLockUpgradableReadGuard<T>>
Attempts to acquire this rwlock with upgradable read access.
If the access could not be granted at this time, then None
is returned.
Otherwise, an RAII guard is returned which will release the shared access
when it is dropped.
This function does not block.
pub fn try_upgradable_read_for(
&self,
timeout: Duration
) -> Option<RwLockUpgradableReadGuard<T>>
[src]
pub fn try_upgradable_read_for(
&self,
timeout: Duration
) -> Option<RwLockUpgradableReadGuard<T>>
Attempts to acquire this rwlock with upgradable read access until a timeout is reached.
If the access could not be granted before the timeout expires, then
None
is returned. Otherwise, an RAII guard is returned which will
release the shared access when it is dropped.
pub fn try_upgradable_read_until(
&self,
timeout: Instant
) -> Option<RwLockUpgradableReadGuard<T>>
[src]
pub fn try_upgradable_read_until(
&self,
timeout: Instant
) -> Option<RwLockUpgradableReadGuard<T>>
Attempts to acquire this rwlock with upgradable read access until a timeout is reached.
If the access could not be granted before the timeout expires, then
None
is returned. Otherwise, an RAII guard is returned which will
release the shared access when it is dropped.
pub unsafe fn raw_unlock_read(&self)
[src]
pub unsafe fn raw_unlock_read(&self)
Releases shared read access of the rwlock.
Safety
This function must only be called if the rwlock was locked using
raw_read
or raw_try_read
, or if an RwLockReadGuard
from this
rwlock was leaked (e.g. with mem::forget
). The rwlock must be locked
with shared read access.
pub unsafe fn raw_unlock_write(&self)
[src]
pub unsafe fn raw_unlock_write(&self)
Releases exclusive write access of the rwlock.
Safety
This function must only be called if the rwlock was locked using
raw_write
or raw_try_write
, or if an RwLockWriteGuard
from this
rwlock was leaked (e.g. with mem::forget
). The rwlock must be locked
with exclusive write access.
pub unsafe fn raw_unlock_upgradable_read(&self)
[src]
pub unsafe fn raw_unlock_upgradable_read(&self)
Releases upgradable read access of the rwlock.
Safety
This function must only be called if the rwlock was locked using
raw_upgradable_read
or raw_try_upgradable_read
, or if an
RwLockUpgradableReadGuard
from this rwlock was leaked (e.g. with
mem::forget
). The rwlock must be locked with upgradable read access.
pub unsafe fn raw_unlock_read_fair(&self)
[src]
pub unsafe fn raw_unlock_read_fair(&self)
Releases shared read access of the rwlock using a fair unlock protocol.
See RwLockReadGuard::unlock_fair
.
Safety
This function must only be called if the rwlock was locked using
raw_write
or raw_try_write
, a raw upgradable read lock was upgraded
using raw_upgrade
or raw_try_upgrade
, or if an RwLockWriteGuard
from this rwlock was leaked (e.g. with mem::forget
). The rwlock must
be locked with exclusive write access.
pub unsafe fn raw_unlock_write_fair(&self)
[src]
pub unsafe fn raw_unlock_write_fair(&self)
Releases exclusive write access of the rwlock using a fair unlock protocol.
See RwLockWriteGuard::unlock_fair
.
Safety
This function must only be called if the rwlock was locked using
raw_write
or raw_try_write
, a raw upgradable read lock was upgraded
using raw_upgrade
or raw_try_upgrade
, or if an RwLockWriteGuard
from this rwlock was leaked (e.g. with mem::forget
). The rwlock must
be locked with exclusive write access.
pub unsafe fn raw_unlock_upgradable_read_fair(&self)
[src]
pub unsafe fn raw_unlock_upgradable_read_fair(&self)
Releases upgradable read access of the rwlock using a fair unlock protocol.
Safety
This function must only be called if the rwlock was locked using
raw_upgradable_read
or raw_try_upgradable_read
, or if an
RwLockUpgradableReadGuard
from this rwlock was leaked (e.g. with
mem::forget
). The rwlock must be locked with upgradable read access.
pub unsafe fn raw_downgrade(&self)
[src]
pub unsafe fn raw_downgrade(&self)
Atomically downgrades a write lock into a shared read lock without allowing any writers to take exclusive access of the lock in the meantime.
See RwLockWriteGuard::downgrade
.
Safety
This function must only be called if the rwlock was locked using
raw_write
or raw_try_write
, or if an RwLockWriteGuard
from this
rwlock was leaked (e.g. with mem::forget
). The rwlock must be locked
with exclusive write access.
pub unsafe fn raw_downgrade_upgradable_read(&self)
[src]
pub unsafe fn raw_downgrade_upgradable_read(&self)
Atomically downgrades an upgradable read lock into a shared read lock without allowing any writers to take exclusive access of the lock in the meantime.
See RwLockUpgradableReadGuard::downgrade
.
Safety
This function must only be called if the rwlock was locked using
raw_upgradable_read
or raw_try_upgradable_read
, or if an
RwLockUpgradableReadGuard
from this rwlock was leaked (e.g. with
mem::forget
). The rwlock must be locked with upgradable read access.
pub fn raw_read(&self)
[src]
pub fn raw_read(&self)
Locks this rwlock with shared read access, blocking the current thread until it can be acquired.
This is similar to read
, except that a RwLockReadGuard
is not
returned. Instead you will need to call raw_unlock
to release the
rwlock.
pub fn raw_try_read(&self) -> bool
[src]
pub fn raw_try_read(&self) -> bool
Attempts to acquire this rwlock with shared read access.
This is similar to try_read
, except that a RwLockReadGuard
is not
returned. Instead you will need to call raw_unlock
to release the
rwlock.
pub fn raw_read_recursive(&self)
[src]
pub fn raw_read_recursive(&self)
Locks this rwlock with shared read access, blocking the current thread until it can be acquired.
This is similar to read_recursive
, except that a RwLockReadGuard
is
not returned. Instead you will need to call raw_unlock
to release the
rwlock.
pub fn raw_try_read_recursive(&self) -> bool
[src]
pub fn raw_try_read_recursive(&self) -> bool
Attempts to acquire this rwlock with shared read access.
This is similar to try_read_recursive
, except that a RwLockReadGuard
is not
returned. Instead you will need to call raw_unlock
to release the
rwlock.
pub fn raw_write(&self)
[src]
pub fn raw_write(&self)
Locks this rwlock with exclusive write access, blocking the current thread until it can be acquired.
This is similar to write
, except that a RwLockReadGuard
is not
returned. Instead you will need to call raw_unlock
to release the
rwlock.
pub fn raw_try_write(&self) -> bool
[src]
pub fn raw_try_write(&self) -> bool
Attempts to lock this rwlock with exclusive write access.
This is similar to try_write
, except that a RwLockReadGuard
is not
returned. Instead you will need to call raw_unlock
to release the
rwlock.
pub fn raw_upgradable_read(&self)
[src]
pub fn raw_upgradable_read(&self)
Locks this rwlock with upgradable read access, blocking the current thread until it can be acquired.
This is similar to upgradable_read
, except that a
RwLockUpgradableReadGuard
is not returned. Instead you will need to call
raw_unlock
to release the rwlock.
pub fn raw_try_upgradable_read(&self) -> bool
[src]
pub fn raw_try_upgradable_read(&self) -> bool
Attempts to acquire this rwlock with upgradable read access.
This is similar to try_upgradable_read
, except that a
RwLockUpgradableReadGuard
is not returned. Instead you will need to call
raw_unlock
to release the rwlock.
pub unsafe fn raw_upgrade(&self)
[src]
pub unsafe fn raw_upgrade(&self)
Upgrades this rwlock from upgradable read access to exclusive write access, blocking the current thread until it can be acquired.
See RwLockUpgradableReadGuard::upgrade
.
Safety
This function must only be called if the rwlock was locked using
raw_upgradable_read
or raw_try_upgradable_read
, or if an
RwLockUpgradableReadGuard
from this rwlock was leaked (e.g. with
mem::forget
). The rwlock must be locked with upgradable read access.
pub unsafe fn raw_try_upgrade(&self) -> bool
[src]
pub unsafe fn raw_try_upgrade(&self) -> bool
Attempts to upgrade this rwlock from upgradable read access to exclusive write access.
See RwLockUpgradableReadGuard::try_upgrade
.
Safety
This function must only be called if the rwlock was locked using
raw_upgradable_read
or raw_try_upgradable_read
, or if an
RwLockUpgradableReadGuard
from this rwlock was leaked (e.g. with
mem::forget
). The rwlock must be locked with upgradable read access.
Trait Implementations
impl Deref for CACHE
impl Deref for CACHE
type Target = RwLock<Cache>
The resulting type after dereferencing.
fn deref(&self) -> &RwLock<Cache>
fn deref(&self) -> &RwLock<Cache>
Dereferences the value.
impl LazyStatic for CACHE
impl LazyStatic for CACHE
fn initialize(lazy: &Self)
fn initialize(lazy: &Self)
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> Erased for T
impl<T> Erased for T
impl<T> Typeable for T where
T: Any,
impl<T> Typeable for T where
T: Any,
impl<T> UnsafeAny for T where
T: Any,
impl<T> UnsafeAny for T where
T: Any,