From 0e2b64878c9630c37cf851c2fb868e098aa70262 Mon Sep 17 00:00:00 2001 From: "Alex M. M" Date: Sun, 17 Jan 2021 02:29:28 +0100 Subject: [PATCH] Allow users to reuse `Http` when building the `Client` (#1189) --- src/client/mod.rs | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index 33036f34fa1..8ab276cdd41 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -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) -> Self { + fn _new() -> Self { Self { data: Some(TypeMap::new()), http: None, @@ -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) -> 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 ",