Skip to content

Commit 8e6e0f5

Browse files
committed
Swap to native async traits where possible
1 parent 53f2e5a commit 8e6e0f5

File tree

10 files changed

+19
-35
lines changed

10 files changed

+19
-35
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ repository = "https://github.com/serenity-rs/poise/"
1212
tokio = { version = "1.25.1", default-features = false } # for async in general
1313
futures-util = { version = "0.3.13", default-features = false } # for async in general
1414
poise_macros = { path = "macros", version = "0.6.1" } # remember to update the version on changes!
15-
async-trait = { version = "0.1.48", default-features = false } # various traits
1615
regex = { version = "1.6.0", default-features = false, features = ["std"] } # prefix
1716
tracing = { version = "0.1.40", features = ["log"] } # warning about weird state
1817
derivative = "2.2.0"

src/argument.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::{
99
/// This is useful if you need to take an argument via a string, but immediately convert it via [`FromStr`].
1010
pub struct StrArg<T>(pub T);
1111

12-
#[async_trait::async_trait]
1312
impl<T> SlashArgument for StrArg<T>
1413
where
1514
T: FromStr,
@@ -40,7 +39,6 @@ where
4039
}
4140
}
4241

43-
#[async_trait::async_trait]
4442
impl<'a, T> PopArgument<'a> for StrArg<T>
4543
where
4644
T: FromStr,

src/choice_parameter.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub trait ChoiceParameter: Sized {
2222
fn localized_name(&self, locale: &str) -> Option<&'static str>;
2323
}
2424

25-
#[async_trait::async_trait]
2625
impl<T: ChoiceParameter> crate::SlashArgument for T {
2726
async fn extract(
2827
_: &serenity::Context,
@@ -55,7 +54,6 @@ impl<T: ChoiceParameter> crate::SlashArgument for T {
5554
}
5655
}
5756

58-
#[async_trait::async_trait]
5957
impl<'a, T: ChoiceParameter> crate::PopArgument<'a> for T {
6058
async fn pop_from(
6159
args: &'a str,

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,6 @@ pub mod samples {
411411
pub use crate::builtins::*;
412412
}
413413

414-
#[doc(hidden)]
415-
pub use {async_trait::async_trait, futures_util};
416-
417414
/// This module re-exports a bunch of items from all over serenity. Useful if you can't
418415
/// remember the full paths of serenity items.
419416
///

src/modal.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Modal trait and utility items for implementing it (mainly for the derive macro)
22
3+
use std::future::Future;
4+
35
use crate::serenity_prelude as serenity;
46

57
/// Meant for use in derived [`Modal::parse`] implementation
@@ -40,10 +42,7 @@ pub fn find_modal_text(
4042

4143
/// Underlying code for the modal spawning convenience function which abstracts over the kind of
4244
/// interaction
43-
async fn execute_modal_generic<
44-
M: Modal,
45-
F: std::future::Future<Output = Result<(), serenity::Error>>,
46-
>(
45+
async fn execute_modal_generic<M: Modal, F: Future<Output = Result<(), serenity::Error>>>(
4746
ctx: &serenity::Context,
4847
create_interaction_response: impl FnOnce(serenity::CreateInteractionResponse) -> F,
4948
modal_custom_id: String,
@@ -169,7 +168,6 @@ pub async fn execute_modal_on_component_interaction<M: Modal>(
169168
/// Ok(())
170169
/// }
171170
/// ```
172-
#[async_trait::async_trait]
173171
pub trait Modal: Sized {
174172
/// Returns an interaction response builder which creates the modal for this type
175173
///
@@ -187,18 +185,24 @@ pub trait Modal: Sized {
187185
///
188186
/// For a variant that is triggered on component interactions, see [`execute_modal_on_component_interaction`].
189187
// TODO: add execute_with_defaults? Or add a `defaults: Option<Self>` param?
190-
async fn execute<U: Send + Sync, E>(
188+
fn execute<U: Send + Sync, E>(
191189
ctx: crate::ApplicationContext<'_, U, E>,
192-
) -> Result<Option<Self>, serenity::Error> {
193-
execute_modal(ctx, None::<Self>, None).await
190+
) -> impl Future<Output = Result<Option<Self>, serenity::Error>> + Send
191+
where
192+
Self: Send,
193+
{
194+
execute_modal(ctx, None::<Self>, None)
194195
}
195196

196197
/// Calls `execute_modal(ctx, Some(defaults), None)`. See [`execute_modal`]
197198
// TODO: deprecate this in favor of execute_modal()?
198-
async fn execute_with_defaults<U: Send + Sync, E>(
199+
fn execute_with_defaults<U: Send + Sync, E>(
199200
ctx: crate::ApplicationContext<'_, U, E>,
200201
defaults: Self,
201-
) -> Result<Option<Self>, serenity::Error> {
202-
execute_modal(ctx, Some(defaults), None).await
202+
) -> impl Future<Output = Result<Option<Self>, serenity::Error>> + Send
203+
where
204+
Self: Send,
205+
{
206+
execute_modal(ctx, Some(defaults), None)
203207
}
204208
}

src/prefix_argument/argument_trait.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@ pub(crate) type PopArgumentResult<'a, T> =
1919
/// does. This is for consistency's sake and also because it keeps open the possibility of parsing whitespace.
2020
///
2121
/// Similar in spirit to [`std::str::FromStr`].
22-
#[async_trait::async_trait]
2322
pub trait PopArgument<'a>: Sized {
2423
/// Pops an argument from the `args` string.
2524
///
2625
/// See the documentation of [`PopArgumentResult`] for the return type.
27-
async fn pop_from(
26+
fn pop_from(
2827
args: &'a str,
2928
attachment_index: usize,
3029
ctx: &serenity::Context,
3130
msg: &serenity::Message,
32-
) -> PopArgumentResult<'a, Self>;
31+
) -> impl std::future::Future<Output = PopArgumentResult<'a, Self>>;
3332
}
3433

35-
#[async_trait::async_trait]
3634
impl<'a> PopArgument<'a> for String {
3735
async fn pop_from(
3836
args: &'a str,
@@ -47,7 +45,6 @@ impl<'a> PopArgument<'a> for String {
4745
}
4846
}
4947

50-
#[async_trait::async_trait]
5148
impl<'a> PopArgument<'a> for bool {
5249
async fn pop_from(
5350
args: &'a str,
@@ -68,7 +65,6 @@ impl<'a> PopArgument<'a> for bool {
6865
}
6966
}
7067

71-
#[async_trait::async_trait]
7268
impl<'a> PopArgument<'a> for serenity::Attachment {
7369
async fn pop_from(
7470
args: &'a str,
@@ -108,7 +104,6 @@ where
108104
/// Implements PopArgument for many types via `[pop_from_via_argumentconvert`].
109105
macro_rules! impl_popargument_via_argumentconvert {
110106
($($type:ty),*) => {$(
111-
#[async_trait::async_trait]
112107
impl<'a> PopArgument<'a> for $type {
113108
async fn pop_from(
114109
args: &'a str,

src/prefix_argument/code_block.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ fn pop_from(args: &str) -> Result<(&str, CodeBlock), CodeBlockError> {
109109
}
110110
}
111111

112-
#[async_trait::async_trait]
113112
impl<'a> PopArgument<'a> for CodeBlock {
114113
/// Parse a single-line or multi-line code block. The output of `Self::code` should mirror what
115114
/// the official Discord client renders, and the output of `Self::language` should mirror the

src/prefix_argument/key_value_args.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ impl KeyValueArgs {
7171
}
7272
}
7373

74-
#[async_trait::async_trait]
7574
impl<'a> PopArgument<'a> for KeyValueArgs {
7675
async fn pop_from(
7776
args: &'a str,

src/slash_argument/slash_trait.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ use crate::serenity::json::*;
88
use crate::{serenity_prelude as serenity, CowVec};
99

1010
/// Implement this trait on types that you want to use as a slash command parameter.
11-
#[async_trait::async_trait]
1211
pub trait SlashArgument: Sized {
1312
/// Extract a Rust value of type T from the slash command argument, given via a [`serenity::ResolvedValue`].
14-
async fn extract(
13+
fn extract(
1514
ctx: &serenity::Context,
1615
interaction: &serenity::CommandInteraction,
1716
value: &serenity::ResolvedValue<'_>,
18-
) -> Result<Self, SlashArgError>;
17+
) -> impl std::future::Future<Output = Result<Self, SlashArgError>>;
1918

2019
/// Create a slash command parameter equivalent to type T.
2120
///
@@ -64,7 +63,6 @@ where
6463
/// Implements `SlashArgument` via `serenity::ArgumentConvert`
6564
macro_rules! impl_for_argumentconvert {
6665
($type:ty) => {
67-
#[async_trait::async_trait]
6866
impl SlashArgument for $type {
6967
async fn extract(
7068
ctx: &serenity::Context,
@@ -86,7 +84,6 @@ impl_for_argumentconvert!(serenity::Message);
8684
/// Implements slash argument trait for integer types
8785
macro_rules! impl_for_integer {
8886
($($t:ty)*) => { $(
89-
#[async_trait::async_trait]
9087
impl SlashArgument for $t {
9188
async fn extract(
9289
_: &serenity::Context,
@@ -120,7 +117,6 @@ impl_for_integer!(i8 i16 i32 i64 isize u8 u16 u32 u64 usize);
120117
/// Versatile macro to implement `SlashArgument` for simple types
121118
macro_rules! impl_slash_argument {
122119
($type:ty, |$ctx:pat, $interaction:pat, $slash_param_type:ident ( $($arg:pat),* )| $extractor:expr) => {
123-
#[async_trait::async_trait]
124120
impl SlashArgument for $type {
125121
async fn extract(
126122
$ctx: &serenity::Context,

0 commit comments

Comments
 (0)