aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-28 17:51:58 -0800
committerAustin Hellyer <[email protected]>2016-11-28 17:51:58 -0800
commit9ef110ec52527e0018c979b0c44a52c98dceafdb (patch)
treee26068dcac610ee62eb6d5099d9916a8f132121d /examples
parentCargo: Don't have bins for examples (diff)
downloadserenity-9ef110ec52527e0018c979b0c44a52c98dceafdb.tar.xz
serenity-9ef110ec52527e0018c979b0c44a52c98dceafdb.zip
Optimize for cached, non-method compiles
Diffstat (limited to 'examples')
-rw-r--r--examples/03_struct_utilities.rs10
-rw-r--r--examples/06_command_framework.rs9
2 files changed, 19 insertions, 0 deletions
diff --git a/examples/03_struct_utilities.rs b/examples/03_struct_utilities.rs
index af00abb..ea91500 100644
--- a/examples/03_struct_utilities.rs
+++ b/examples/03_struct_utilities.rs
@@ -1,8 +1,13 @@
+//! Requires the 'methods' feature flag be enabled.
+
extern crate serenity;
+#[cfg(feature = "methods")]
use serenity::Client;
+#[cfg(feature = "methods")]
use std::env;
+#[cfg(feature = "methods")]
fn main() {
// Configure the client with your Discord bot token in the environment.
let token = env::var("DISCORD_TOKEN")
@@ -21,3 +26,8 @@ fn main() {
let _ = client.start();
}
+
+#[cfg(not(feature = "methods"))]
+fn main() {
+ println!("The 'methods' feature flag is required for this example.");
+}
diff --git a/examples/06_command_framework.rs b/examples/06_command_framework.rs
index 38f756d..78e4e9e 100644
--- a/examples/06_command_framework.rs
+++ b/examples/06_command_framework.rs
@@ -55,10 +55,19 @@ fn dog_command(context: &Context, _msg: &Message, _args: Vec<String>) {
let _ = context.say(":dog:");
}
+// `Message::reply` is only compiled if the `methods` feature flag is enabled.
+#[cfg(feature = "methods")]
fn ping_command(_context: &Context, message: &Message, _args: Vec<String>) {
let _ = message.reply("Pong!");
}
+#[cfg(not(feature = "methods"))]
+fn ping_command(context: &Context, message: &Message, _args: Vec<String>) {
+ if let Err(why) = context.say(&format!("{}: Pong!", message.author)) {
+ println!("Error sending message: {:?}", why);
+ }
+}
+
fn owner_check(_context: &Context, message: &Message) -> bool {
// Replace 7 with your ID
message.author.id == 7