[][src]Struct serenity::cache::Settings

pub struct Settings {
    pub max_messages: usize,
    pub cache_lock_time: Option<Duration>,
    // some fields omitted
}

Settings for the cache.

Examples

Create new settings, specifying the maximum number of messages:

use serenity::cache::Settings as CacheSettings;

let mut settings = CacheSettings::new();
settings.max_messages(10);

Fields

The maximum number of messages to store in a channel's message cache.

Defaults to 0.

The Duration cache updates will try to acquire write-locks for.

Defaults to 10 milliseconds.

Note: If set to None, cache updates will acquire write-lock until available, potentially deadlocking.

Methods

impl Settings
[src]

Creates new settings to be used with a cache.

Sets the maximum number of messages to cache in a channel.

Refer to max_messages for more information.

Examples

Set the maximum number of messages to cache:

use serenity::cache::Settings;

let mut settings = Settings::new();
settings.max_messages(10);

Sets the duration that the cache will try to aquire a write lock.

Refer to cache_lock_time for more information.

Note: Should be set before the client gets started, as it can not be changed after the first read of the duration.

Examples

Set the time that it will try to aquire a lock.

use std::time::Duration;
use std::env;
use serenity::prelude::*;

struct Handler;

impl EventHandler for Handler {}

fn main() {
    let token = env::var("DISCORD_TOKEN")
       .expect("Expected a token in the environment");
    serenity::CACHE
       .write().settings_mut()
       .cache_lock_time(Some(Duration::from_secs(1)));
    let mut client = Client::new(&token, Handler).unwrap();

    if let Err(why) = client.start() {
       println!("Client error: {:?}", why);
    }
}

Trait Implementations

impl Default for Settings
[src]

Returns the "default value" for a type. Read more

impl Clone for Settings
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Settings
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for Settings

impl Sync for Settings

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 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> Typeable for T where
    T: Any

Get the TypeId of this object.

impl<T> DebugAny for T where
    T: Any + Debug
[src]

impl<T> CloneAny for T where
    T: Clone + Any
[src]

impl<T> UnsafeAny for T where
    T: Any