-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change get_bots and remove async_trait dependency
- Loading branch information
Showing
8 changed files
with
113 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,20 @@ | ||
use crate::{InnerClient, Stats}; | ||
use crate::InnerClient; | ||
use std::sync::Arc; | ||
|
||
#[async_trait::async_trait] | ||
pub trait IntoClientSealed { | ||
type ArcInner: Send + Sync + 'static; | ||
|
||
fn get_arc(&self) -> Arc<Self::ArcInner>; | ||
async fn post_stats(arc: &Self::ArcInner, stats: &Stats); | ||
pub trait AsClientSealed { | ||
fn as_client(&self) -> Arc<InnerClient>; | ||
} | ||
|
||
/// A private trait that represents any datatype that can be interpreted as a [Top.gg API](https://docs.top.gg) Client. | ||
/// | ||
/// This can either be a reference to an existing [`Client`][crate::Client] or a [`&str`][core::str] representing a [Top.gg API](https://docs.top.gg) token. | ||
pub trait IntoClient: IntoClientSealed {} | ||
|
||
#[async_trait::async_trait] | ||
impl IntoClientSealed for str { | ||
type ArcInner = InnerClient; | ||
pub trait AsClient: AsClientSealed {} | ||
|
||
impl AsClientSealed for str { | ||
#[inline(always)] | ||
fn get_arc(&self) -> Arc<Self::ArcInner> { | ||
fn as_client(&self) -> Arc<InnerClient> { | ||
Arc::new(InnerClient::new(String::from(self))) | ||
} | ||
|
||
#[inline(always)] | ||
async fn post_stats(arc: &Self::ArcInner, stats: &Stats) { | ||
let _ = arc.post_stats(stats).await; | ||
} | ||
} | ||
|
||
impl IntoClient for str {} | ||
impl AsClient for str {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.