1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use super::builder::ShardScheme;
use crate::shard::{Config as ShardConfig, ResumeSession};
use std::{collections::HashMap, sync::Arc};
use twilight_gateway_queue::Queue;
use twilight_http::Client;

/// Built configuration for a [`Cluster`].
///
/// [`Cluster`]: crate::Cluster
#[derive(Debug)]
pub struct Config {
    pub(super) http_client: Client,
    pub(super) shard_config: ShardConfig,
    pub(super) shard_scheme: ShardScheme,
    pub(super) queue: Arc<Box<dyn Queue>>,
    pub(super) resume_sessions: HashMap<u64, ResumeSession>,
}

impl Config {
    /// Return an immutable reference to the `twilight_http` client used by the
    /// cluster and shards to get the gateway information.
    ///
    /// Refer to [`ClusterBuilder::http_client`] for the default value.
    ///
    /// [`ClusterBuilder::http_client`]: super::ClusterBuilder::http_client
    pub fn http_client(&self) -> &Client {
        &self.http_client
    }

    /// Return an immutable reference to the configuration used to create
    /// shards.
    ///
    /// Refer to [`ShardBuilder`]'s methods for the default values.
    ///
    /// [`ShardBuilder`]: crate::shard::ShardBuilder#impl
    pub fn shard_config(&self) -> &ShardConfig {
        &self.shard_config
    }

    /// Return an immutable reference to the shard scheme used to start shards.
    ///
    /// Refer to [`ClusterBuilder::shard_scheme`] for the default value.
    ///
    /// [`ClusterBuilder::shard_scheme`]: super::ClusterBuilder::shard_scheme
    pub fn shard_scheme(&self) -> &ShardScheme {
        &self.shard_scheme
    }

    /// Return an immutable reference to the queue used for initiating shard
    /// sessions.
    pub fn queue(&self) -> &Arc<Box<dyn Queue>> {
        &self.queue
    }
}

#[cfg(test)]
mod tests {
    use super::Config;
    use static_assertions::assert_impl_all;
    use std::fmt::Debug;

    assert_impl_all!(Config: Debug, Send, Sync);
}