Skip to content

Commit 590cc89

Browse files
authored
Rewrite builders to take Cows (#2688)
1 parent 60d589b commit 590cc89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1160
-883
lines changed

examples/e14_slash_commands/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "e14_slash_commands"
33
version = "0.1.0"
44
authors = ["my name <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66

77
[dependencies]
88
serenity = { path = "../../", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "collector"] }

examples/e14_slash_commands/src/commands/attachmentinput.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn run(options: &[ResolvedOption]) -> String {
1212
}
1313
}
1414

15-
pub fn register() -> CreateCommand {
15+
pub fn register() -> CreateCommand<'static> {
1616
CreateCommand::new("attachmentinput")
1717
.description("Test command for attachment input")
1818
.add_option(

examples/e14_slash_commands/src/commands/id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn run(options: &[ResolvedOption]) -> String {
1212
}
1313
}
1414

15-
pub fn register() -> CreateCommand {
15+
pub fn register() -> CreateCommand<'static> {
1616
CreateCommand::new("id").description("Get a user id").add_option(
1717
CreateCommandOption::new(CommandOptionType::User, "id", "The user to lookup")
1818
.required(true),

examples/e14_slash_commands/src/commands/modal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ pub async fn run(ctx: &Context, interaction: &CommandInteraction) -> Result<(),
2626
Ok(())
2727
}
2828

29-
pub fn register() -> CreateCommand {
29+
pub fn register() -> CreateCommand<'static> {
3030
CreateCommand::new("modal").description("Asks some details about you")
3131
}

examples/e14_slash_commands/src/commands/numberinput.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serenity::builder::{CreateCommand, CreateCommandOption};
22
use serenity::model::application::CommandOptionType;
33

4-
pub fn register() -> CreateCommand {
4+
pub fn register() -> CreateCommand<'static> {
55
CreateCommand::new("numberinput")
66
.description("Test command for number input")
77
.add_option(

examples/e14_slash_commands/src/commands/ping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ pub fn run(_options: &[ResolvedOption]) -> String {
55
"Hey, I'm alive!".to_string()
66
}
77

8-
pub fn register() -> CreateCommand {
8+
pub fn register() -> CreateCommand<'static> {
99
CreateCommand::new("ping").description("A ping command")
1010
}

examples/e14_slash_commands/src/commands/welcome.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
use std::borrow::Cow;
2+
use std::collections::HashMap;
3+
14
use serenity::builder::{CreateCommand, CreateCommandOption};
25
use serenity::model::application::CommandOptionType;
36

4-
pub fn register() -> CreateCommand {
7+
fn new_map<'a>(key: &'a str, value: &'a str) -> HashMap<Cow<'a, str>, Cow<'a, str>> {
8+
let mut map = HashMap::with_capacity(1);
9+
map.insert(Cow::Borrowed(key), Cow::Borrowed(value));
10+
map
11+
}
12+
13+
pub fn register() -> CreateCommand<'static> {
514
CreateCommand::new("welcome")
615
.description("Welcome a user")
716
.name_localized("de", "begrüßen")
@@ -20,27 +29,28 @@ pub fn register() -> CreateCommand {
2029
.add_string_choice_localized(
2130
"Welcome to our cool server! Ask me if you need help",
2231
"pizza",
23-
[(
32+
new_map(
2433
"de",
2534
"Willkommen auf unserem coolen Server! Frag mich, falls du Hilfe brauchst",
26-
)],
35+
),
36+
)
37+
.add_string_choice_localized(
38+
"Hey, do you want a coffee?",
39+
"coffee",
40+
new_map("de", "Hey, willst du einen Kaffee?"),
2741
)
28-
.add_string_choice_localized("Hey, do you want a coffee?", "coffee", [(
29-
"de",
30-
"Hey, willst du einen Kaffee?",
31-
)])
3242
.add_string_choice_localized(
3343
"Welcome to the club, you're now a good person. Well, I hope.",
3444
"club",
35-
[(
45+
new_map(
3646
"de",
3747
"Willkommen im Club, du bist jetzt ein guter Mensch. Naja, hoffentlich.",
38-
)],
48+
),
3949
)
4050
.add_string_choice_localized(
4151
"I hope that you brought a controller to play together!",
4252
"game",
43-
[("de", "Ich hoffe du hast einen Controller zum Spielen mitgebracht!")],
53+
new_map("de", "Ich hoffe du hast einen Controller zum Spielen mitgebracht!"),
4454
),
4555
)
4656
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use serenity::builder::CreateCommand;
22

3-
pub fn register() -> CreateCommand {
3+
pub fn register() -> CreateCommand<'static> {
44
CreateCommand::new("wonderful_command").description("An amazing command")
55
}

examples/e14_slash_commands/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl EventHandler for Handler {
4949
);
5050

5151
let commands = guild_id
52-
.set_commands(&ctx.http, vec![
52+
.set_commands(&ctx.http, &[
5353
commands::ping::register(),
5454
commands::id::register(),
5555
commands::welcome::register(),

examples/e17_message_components/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Cow;
12
use std::env;
23
use std::time::Duration;
34

@@ -40,13 +41,13 @@ impl EventHandler for Handler {
4041
&ctx,
4142
CreateMessage::new().content("Please select your favorite animal").select_menu(
4243
CreateSelectMenu::new("animal_select", CreateSelectMenuKind::String {
43-
options: vec![
44+
options: Cow::Borrowed(&[
4445
CreateSelectMenuOption::new("🐈 meow", "Cat"),
4546
CreateSelectMenuOption::new("🐕 woof", "Dog"),
4647
CreateSelectMenuOption::new("🐎 neigh", "Horse"),
4748
CreateSelectMenuOption::new("🦙 hoooooooonk", "Alpaca"),
4849
CreateSelectMenuOption::new("🦀 crab rave", "Ferris"),
49-
],
50+
]),
5051
})
5152
.custom_id("animal_select")
5253
.placeholder("No animal selected"),

0 commit comments

Comments
 (0)