From 5ed9f470fdb5545c94cef4983c2e23b6b78dd5a2 Mon Sep 17 00:00:00 2001 From: Vilgot Fredenberg Date: Sat, 22 Jan 2022 17:52:52 +0100 Subject: [PATCH 1/2] feat(gateway)!: Take constructors take `String`, not `Into` This was intened to land at the same time as `twilight_http::Client` constructor's got rewored in the same way. --- gateway/src/cluster/builder.rs | 6 +++--- gateway/src/cluster/impl.rs | 7 ++----- gateway/src/shard/builder.rs | 13 +++++-------- gateway/src/shard/impl.rs | 4 ++-- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/gateway/src/cluster/builder.rs b/gateway/src/cluster/builder.rs index cf3c049082d..dcc257b238c 100644 --- a/gateway/src/cluster/builder.rs +++ b/gateway/src/cluster/builder.rs @@ -44,7 +44,7 @@ pub struct ClusterBuilder(ClusterConfig, ShardBuilder); impl ClusterBuilder { /// Create a new builder to construct and configure a cluster. - pub fn new(token: impl Into, intents: Intents) -> Self { + pub fn new(token: String, intents: Intents) -> Self { Self( ClusterConfig { shard_scheme: ShardScheme::Auto, @@ -249,8 +249,8 @@ impl ClusterBuilder { } } -impl> From<(T, Intents)> for ClusterBuilder { - fn from((token, intents): (T, Intents)) -> Self { +impl From<(String, Intents)> for ClusterBuilder { + fn from((token, intents): (String, Intents)) -> Self { Self::new(token, intents) } } diff --git a/gateway/src/cluster/impl.rs b/gateway/src/cluster/impl.rs index e18849448c6..dbab1a77b11 100644 --- a/gateway/src/cluster/impl.rs +++ b/gateway/src/cluster/impl.rs @@ -271,10 +271,7 @@ impl Cluster { /// there was an HTTP error Retrieving the gateway information. /// /// [`builder`]: Self::builder - pub async fn new( - token: impl Into, - intents: Intents, - ) -> Result<(Self, Events), ClusterStartError> { + pub async fn new(token: String, intents: Intents) -> Result<(Self, Events), ClusterStartError> { Self::builder(token, intents).build().await } @@ -388,7 +385,7 @@ impl Cluster { /// } /// # Ok(()) } /// ``` - pub fn builder(token: impl Into, intents: Intents) -> ClusterBuilder { + pub fn builder(token: String, intents: Intents) -> ClusterBuilder { ClusterBuilder::new(token, intents) } diff --git a/gateway/src/shard/builder.rs b/gateway/src/shard/builder.rs index c68e8ce01a9..50936c93832 100644 --- a/gateway/src/shard/builder.rs +++ b/gateway/src/shard/builder.rs @@ -167,11 +167,7 @@ impl ShardBuilder { /// Create a new builder to configure and construct a shard. /// /// Refer to each method to learn their default values. - pub fn new(token: impl Into, intents: Intents) -> Self { - Self::_new(token.into(), intents) - } - - fn _new(mut token: String, intents: Intents) -> Self { + pub fn new(mut token: String, intents: Intents) -> Self { if !token.starts_with("Bot ") { token.insert_str(0, "Bot "); } @@ -319,6 +315,7 @@ impl ShardBuilder { /// commands": /// /// ```no_run + /// use std::env; /// use twilight_gateway::{Intents, Shard}; /// use twilight_model::gateway::{ /// payload::outgoing::update_presence::UpdatePresencePayload, @@ -326,7 +323,7 @@ impl ShardBuilder { /// }; /// /// # fn main() -> Result<(), Box> { - /// let shard = Shard::builder("token", Intents::empty()) + /// let shard = Shard::builder(env::var("token")?, Intents::empty()) /// .presence(UpdatePresencePayload::new( /// vec![MinimalActivity { /// kind: ActivityType::Playing, @@ -413,8 +410,8 @@ impl ShardBuilder { } } -impl> From<(T, Intents)> for ShardBuilder { - fn from((token, intents): (T, Intents)) -> Self { +impl From<(String, Intents)> for ShardBuilder { + fn from((token, intents): (String, Intents)) -> Self { Self::new(token, intents) } } diff --git a/gateway/src/shard/impl.rs b/gateway/src/shard/impl.rs index 197e69b5caf..92033d8bc15 100644 --- a/gateway/src/shard/impl.rs +++ b/gateway/src/shard/impl.rs @@ -432,7 +432,7 @@ impl Shard { /// ``` /// /// [`start`]: Self::start - pub fn new(token: impl Into, intents: Intents) -> (Self, Events) { + pub fn new(token: String, intents: Intents) -> (Self, Events) { Self::builder(token, intents).build() } @@ -455,7 +455,7 @@ impl Shard { /// Create a builder to configure and construct a shard. /// /// Refer to the builder for more information. - pub fn builder(token: impl Into, intents: Intents) -> ShardBuilder { + pub fn builder(token: String, intents: Intents) -> ShardBuilder { ShardBuilder::new(token, intents) } From b6af8e0c2643beda078458dafbea7c3b8d13e134 Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Sat, 22 Jan 2022 14:01:05 -0500 Subject: [PATCH 2/2] token consistency --- gateway/src/shard/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/src/shard/builder.rs b/gateway/src/shard/builder.rs index 50936c93832..2bd7b7080f7 100644 --- a/gateway/src/shard/builder.rs +++ b/gateway/src/shard/builder.rs @@ -323,7 +323,7 @@ impl ShardBuilder { /// }; /// /// # fn main() -> Result<(), Box> { - /// let shard = Shard::builder(env::var("token")?, Intents::empty()) + /// let shard = Shard::builder(env::var("DISCORD_TOKEN")?, Intents::empty()) /// .presence(UpdatePresencePayload::new( /// vec![MinimalActivity { /// kind: ActivityType::Playing,