-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement generics commands (#219)
Backport of #206
- Loading branch information
Showing
2 changed files
with
25 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//! If you need it, poise-annotated command functions can also be generic over the user data type | ||
//! or error type | ||
//! | ||
//! The original use case for this feature was to have the same command in two different bots | ||
#[poise::command(slash_command)] | ||
pub async fn example<U: Sync, E>(ctx: poise::Context<'_, U, E>) -> Result<(), E> { | ||
ctx.say(format!( | ||
"My user data type is {} and the error type is {}", | ||
std::any::type_name::<U>(), | ||
std::any::type_name::<E>() | ||
)) | ||
.await | ||
.unwrap(); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let _example1 = example::<(), ()>(); | ||
let _example2 = example::<String, Box<dyn std::error::Error>>(); | ||
} |
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