Skip to content

Commit

Permalink
Allow users to reuse Http when building the Client (#1189)
Browse files Browse the repository at this point in the history
  • Loading branch information
arqunis authored Jan 17, 2021
1 parent cb6b528 commit 0e2b648
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,7 @@ pub struct ClientBuilder<'a> {

#[cfg(feature = "gateway")]
impl<'a> ClientBuilder<'a> {
/// Construct a new builder to call methods on for the client construction.
/// The `token` will automatically be prefixed "Bot " if not already.
///
/// **Panic**:
/// If you enabled the `framework`-feature (on by default), you must specify
/// a framework via the [`framework`] or [`framework_arc`] method,
/// otherwise awaiting the builder will cause a panic.
///
/// [`framework`]: Self::framework
/// [`framework_arc`]: Self::framework_arc
pub fn new(token: impl AsRef<str>) -> Self {
fn _new() -> Self {
Self {
data: Some(TypeMap::new()),
http: None,
Expand All @@ -111,7 +101,38 @@ impl<'a> ClientBuilder<'a> {
voice_manager: None,
event_handler: None,
raw_event_handler: None,
}.token(token)
}
}

/// Construct a new builder to call methods on for the client construction.
/// The `token` will automatically be prefixed "Bot " if not already.
///
/// **Panic**:
/// If you have enabled the `framework`-feature (on by default), you must specify
/// a framework via the [`framework`] or [`framework_arc`] method,
/// otherwise awaiting the builder will cause a panic.
///
/// [`framework`]: Self::framework
/// [`framework_arc`]: Self::framework_arc
pub fn new(token: impl AsRef<str>) -> Self {
Self::_new().token(token)
}

/// Construct a new builder with a [`Http`] instance to calls methods on
/// for the client construction.
///
/// **Panic**:
/// If you have enabled the `framework`-feature (on by default), you must specify
/// a framework via the [`framework`] or [`framework_arc`] method,
/// otherwise awaiting the builder will cause a panic.
///
/// [`Http`]: crate::http::Http
/// [`framework`]: Self::framework
/// [`framework_arc`]: Self::framework_arc
pub fn new_with_http(http: Http) -> Self {
let mut c = Self::_new();
c.http = Some(http);
c
}

/// Sets a token for the bot. If the token is not prefixed "Bot ",
Expand Down

0 comments on commit 0e2b648

Please sign in to comment.