aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-04-26 21:02:02 -0700
committerKen Swenson <[email protected]>2018-11-06 20:30:49 -0500
commit0de0a81be06268f8ec57c8d825cbc70355fe869a (patch)
tree9cfeaf04035c5623c720a6252be9470a03ccbd8f /examples
parentPermit sending files through the `CreateMessage` builder. (diff)
downloadserenity-0de0a81be06268f8ec57c8d825cbc70355fe869a.tar.xz
serenity-0de0a81be06268f8ec57c8d825cbc70355fe869a.zip
Make builders mutably borrowed
Change the builders so that they are now mutably borrowed, accepting `&mut self` instead of `self`. Their methods now return `()` instead of `Self`. Upgrade path: Change code such as the following: ```rust channel.send_message(|m| m .embed(|e| e .description("test") .title("title"))); ``` to the following style: ```rust channel.send_message(|mut m| { m.embed(|mut e| { e.description("test"); e.title("title"); e }); m }); ``` Closes #159.
Diffstat (limited to 'examples')
-rw-r--r--examples/03_struct_utilities/src/main.rs8
-rw-r--r--examples/11_create_message_builder/src/main.rs33
2 files changed, 29 insertions, 12 deletions
diff --git a/examples/03_struct_utilities/src/main.rs b/examples/03_struct_utilities/src/main.rs
index bd2b545..09e9c37 100644
--- a/examples/03_struct_utilities/src/main.rs
+++ b/examples/03_struct_utilities/src/main.rs
@@ -18,7 +18,13 @@ impl EventHandler for Handler {
// In this case, you can direct message a User directly by simply
// calling a method on its instance, with the content of the
// message.
- if let Err(why) = msg.author.dm(|m| m.content("Hello!")) {
+ let dm = msg.author.dm(|mut m| {
+ m.content("Hello!");
+
+ m
+ });
+
+ if let Err(why) = dm {
println!("Error when direct messaging user: {:?}", why);
}
}
diff --git a/examples/11_create_message_builder/src/main.rs b/examples/11_create_message_builder/src/main.rs
index ff6a220..e09d442 100644
--- a/examples/11_create_message_builder/src/main.rs
+++ b/examples/11_create_message_builder/src/main.rs
@@ -13,19 +13,30 @@ impl EventHandler for Handler {
// The create message builder allows you to easily create embeds and messages
// using a builder syntax.
// This example will create a message that says "Hello, World!", with an embed that has
- // a title, description, three fields, and footer.
- if let Err(why) = msg.channel_id.send_message(|m| m
- .content("Hello, World!")
- .embed(|e| e
- .title("This is a title")
- .description("This is a description")
- .fields(vec![
+ // a title, description, three fields, and a footer.
+ let msg = msg.channel_id.send_message(|mut m| {
+ m.content("Hello, World!");
+ m.embed(|mut e| {
+ e.title("This is a title");
+ e.description("This is a description");
+ e.fields(vec![
("This is the first field", "This is a field body", true),
("This is the second field", "Both of these fields are inline", true),
- ])
- .field("This is the third field", "This is not an inline field", false)
- .footer(|f| f
- .text("This is a footer")))) {
+ ]);
+ e.field("This is the third field", "This is not an inline field", false);
+ e.footer(|mut f| {
+ f.text("This is a footer");
+
+ f
+ });
+
+ e
+ });
+
+ m
+ });
+
+ if let Err(why) = msg {
println!("Error sending message: {:?}", why);
}
}