Skip to content

Commit

Permalink
feat(gateway)!: constructors take String, not Into<String> (#1481)
Browse files Browse the repository at this point in the history
This was intened to land at the same time as `twilight_http::Client`
constructor's got reworked in the same way.

Co-authored-by: Zeyla Hellyer <[email protected]>
  • Loading branch information
vilgotf and zeylahellyer authored Jan 22, 2022
1 parent e3e16e2 commit 3aeace7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
6 changes: 3 additions & 3 deletions gateway/src/cluster/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, intents: Intents) -> Self {
pub fn new(token: String, intents: Intents) -> Self {
Self(
ClusterConfig {
shard_scheme: ShardScheme::Auto,
Expand Down Expand Up @@ -249,8 +249,8 @@ impl ClusterBuilder {
}
}

impl<T: Into<String>> 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)
}
}
Expand Down
7 changes: 2 additions & 5 deletions gateway/src/cluster/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
intents: Intents,
) -> Result<(Self, Events), ClusterStartError> {
pub async fn new(token: String, intents: Intents) -> Result<(Self, Events), ClusterStartError> {
Self::builder(token, intents).build().await
}

Expand Down Expand Up @@ -388,7 +385,7 @@ impl Cluster {
/// }
/// # Ok(()) }
/// ```
pub fn builder(token: impl Into<String>, intents: Intents) -> ClusterBuilder {
pub fn builder(token: String, intents: Intents) -> ClusterBuilder {
ClusterBuilder::new(token, intents)
}

Expand Down
13 changes: 5 additions & 8 deletions gateway/src/shard/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, 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 ");
}
Expand Down Expand Up @@ -319,14 +315,15 @@ impl ShardBuilder {
/// commands":
///
/// ```no_run
/// use std::env;
/// use twilight_gateway::{Intents, Shard};
/// use twilight_model::gateway::{
/// payload::outgoing::update_presence::UpdatePresencePayload,
/// presence::{ActivityType, MinimalActivity, Status},
/// };
///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let shard = Shard::builder("token", Intents::empty())
/// let shard = Shard::builder(env::var("DISCORD_TOKEN")?, Intents::empty())
/// .presence(UpdatePresencePayload::new(
/// vec![MinimalActivity {
/// kind: ActivityType::Playing,
Expand Down Expand Up @@ -413,8 +410,8 @@ impl ShardBuilder {
}
}

impl<T: Into<String>> 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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions gateway/src/shard/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl Shard {
/// ```
///
/// [`start`]: Self::start
pub fn new(token: impl Into<String>, intents: Intents) -> (Self, Events) {
pub fn new(token: String, intents: Intents) -> (Self, Events) {
Self::builder(token, intents).build()
}

Expand All @@ -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<String>, intents: Intents) -> ShardBuilder {
pub fn builder(token: String, intents: Intents) -> ShardBuilder {
ShardBuilder::new(token, intents)
}

Expand Down

0 comments on commit 3aeace7

Please sign in to comment.