Skip to content

Commit

Permalink
Update to Rust 2018 (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakelezz authored and arqunis committed Apr 6, 2019
1 parent 62bdf7a commit 21518c8
Show file tree
Hide file tree
Showing 109 changed files with 394 additions and 408 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ http = ["reqwest", "lazy_static"]
model = ["builder", "http"]
standard_framework = ["framework"]
utils = ["base64"]
voice = ["byteorder", "gateway", "opus", "sodiumoxide"]
voice = ["byteorder", "gateway", "opus", "rand", "sodiumoxide"]

[package.metadata.docs.rs]
all-features = true
1 change: 1 addition & 0 deletions examples/01_basic_ping_bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "01_basic_ping_bot"
version = "0.1.0"
authors = ["my name <my@email.address>"]
edition = "2018"

[dependencies]
serenity = { path = "../../", default-features = true }
2 changes: 0 additions & 2 deletions examples/01_basic_ping_bot/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate serenity;

use std::env;

use serenity::{
Expand Down
1 change: 1 addition & 0 deletions examples/02_transparent_guild_sharding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "02_transparent_guild_sharding"
version = "0.1.0"
authors = ["my name <my@email.address>"]
edition = "2018"

[dependencies]
serenity = { path = "../../" }
2 changes: 0 additions & 2 deletions examples/02_transparent_guild_sharding/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate serenity;

use std::env;

use serenity::{
Expand Down
1 change: 1 addition & 0 deletions examples/03_struct_utilities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "03_struct_utilities"
version = "0.1.0"
authors = ["my name <my@email.address>"]
edition = "2018"

[dependencies]
serenity = { path = "../../" }
2 changes: 0 additions & 2 deletions examples/03_struct_utilities/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate serenity;

use std::env;

use serenity::{
Expand Down
2 changes: 0 additions & 2 deletions examples/04_message_builder/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate serenity;

use std::env;

use serenity::{
Expand Down
1 change: 1 addition & 0 deletions examples/05_command_framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "05_command_framework"
version = "0.1.0"
authors = ["my name <my@email.address>"]
edition = "2018"

[dependencies.serenity]
features = ["framework", "standard_framework"]
Expand Down
6 changes: 1 addition & 5 deletions examples/05_command_framework/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@
//! git = "https://github.com/serenity-rs/serenity.git"
//! features = ["framework", "standard_framework"]
//! ```
#[macro_use]
extern crate serenity;
extern crate typemap;

use std::{collections::HashMap, env, fmt::Write, sync::Arc};

use serenity::{
command,
client::bridge::gateway::{ShardId, ShardManager},
framework::standard::{
help_commands, Args, CommandOptions, DispatchError, HelpBehaviour, StandardFramework,
Expand Down
4 changes: 4 additions & 0 deletions examples/06_voice/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
name = "06_voice"
version = "0.1.0"
authors = ["my name <my@email.address>"]
edition = "2018"

[dependencies]
typemap = "0.3"

[dependencies.serenity]
features = ["cache", "framework", "standard_framework", "voice"]
Expand Down
5 changes: 1 addition & 4 deletions examples/06_voice/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
//! git = "https://github.com/serenity-rs/serenity.git"
//! features = ["cache", "framework", "standard_framework", "voice"]
//! ```
#[macro_use] extern crate serenity;
extern crate typemap;

use std::{env, sync::Arc};

// Import the client's bridge to the voice manager. Since voice is a standalone
Expand All @@ -26,6 +22,7 @@ use serenity::client::bridge::voice::ClientVoiceManager;
use serenity::{client::{Context}, prelude::Mutex};

use serenity::{
command,
client::{CACHE, Client, EventHandler},
framework::StandardFramework,
model::{channel::Message, gateway::Ready, misc::Mentionable},
Expand Down
7 changes: 4 additions & 3 deletions examples/07_sample_bot_structure/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
name = "07_sample_bot_structure"
version = "0.1.0"
authors = ["my name <my@email.address>"]
edition = "2018"

[dependencies]
env_logger = "~0.4"
kankyo = "~0.1"
log = "~0.3"
env_logger = "0.6"
kankyo = "0.2"
log = "0.4"

[dependencies.serenity]
features = ["cache", "framework", "standard_framework"]
Expand Down
2 changes: 2 additions & 0 deletions examples/07_sample_bot_structure/src/commands/math.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use serenity::command;

command!(multiply(_ctx, msg, args) {
let one = args.single::<f64>().unwrap();
let two = args.single::<f64>().unwrap();
Expand Down
2 changes: 2 additions & 0 deletions examples/07_sample_bot_structure/src/commands/meta.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use serenity::command;

command!(ping(_ctx, msg) {
let _ = msg.channel_id.say("Pong!");
});
2 changes: 2 additions & 0 deletions examples/07_sample_bot_structure/src/commands/owner.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use serenity::command;

command!(quit(ctx, msg, _args) {
ctx.quit();

Expand Down
11 changes: 3 additions & 8 deletions examples/07_sample_bot_structure/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
//! git = "https://github.com/serenity-rs/serenity.git"
//! features = ["framework", "standard_framework"]
//! ```
#[macro_use] extern crate log;
#[macro_use] extern crate serenity;

extern crate env_logger;
extern crate kankyo;

mod commands;

use std::{collections::HashSet, env};
Expand All @@ -26,6 +19,8 @@ use serenity::{
http,
};

use log::{error, info};

struct Handler;

impl EventHandler for Handler {
Expand All @@ -47,7 +42,7 @@ fn main() {
//
// In this case, a good default is setting the environment variable
// `RUST_LOG` to debug`.
env_logger::init().expect("Failed to initialize env_logger");
env_logger::init();

let token = env::var("DISCORD_TOKEN")
.expect("Expected a token in the environment");
Expand Down
5 changes: 3 additions & 2 deletions examples/08_env_logging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
name = "08_env_logging"
version = "0.1.0"
authors = ["my name <my@email.address>"]
edition = "2018"

[dependencies]
env_logger = "~0.4"
log = "~0.3"
env_logger = "0.6"
log = "0.4"

[dependencies.serenity]
features = ["client"]
Expand Down
9 changes: 3 additions & 6 deletions examples/08_env_logging/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#[macro_use] extern crate log;

extern crate env_logger;
extern crate serenity;

use std::env;

use serenity::{
model::{event::ResumedEvent, gateway::Ready},
prelude::*,
};

use log::{debug, error, info};

struct Handler;

impl EventHandler for Handler {
Expand All @@ -33,7 +30,7 @@ fn main() {
//
// For example, you can say to log all levels INFO and up via setting the
// environment variable `RUST_LOG` to `INFO`.
env_logger::init().expect("Unable to init env_logger");
env_logger::init();

// Configure the client with your Discord bot token in the environment.
let token = env::var("DISCORD_TOKEN")
Expand Down
5 changes: 3 additions & 2 deletions examples/09_shard_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
name = "09_shard_manager"
version = "0.1.0"
authors = ["my name <my@email.address>"]
edition = "2018"

[dependencies]
env_logger = "~0.4"
log = "~0.4"
env_logger = "0.6"
log = "0.4"

[dependencies.serenity]
features = ["client"]
Expand Down
3 changes: 0 additions & 3 deletions examples/09_shard_manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
//!
//! Note that it may take a minute or more for a latency to be recorded or to
//! update, depending on how often Discord tells the client to send a heartbeat.
extern crate serenity;

use std::{env, thread, time::Duration};

use serenity::{
Expand Down
6 changes: 4 additions & 2 deletions examples/10_voice_receive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
name = "10_voice_receive"
version = "0.1.0"
authors = ["my name <my@email.address>"]
edition = "2018"

[dependencies]
env_logger = "~0.4"
log = "~0.4"
env_logger = "0.6"
log = "0.4"
typemap = "0.3"

[dependencies.serenity]
features = ["client", "standard_framework", "voice"]
Expand Down
6 changes: 1 addition & 5 deletions examples/10_voice_receive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
//! git = "https://github.com/serenity-rs/serenity.git"
//! features = ["client", "standard_framework", "voice"]
//! ```
#[macro_use] extern crate serenity;

extern crate typemap;

use std::{env, sync::Arc};

use serenity::{
command,
client::{bridge::voice::ClientVoiceManager, CACHE, Client, Context, EventHandler},
framework::StandardFramework,
model::{channel::Message, gateway::Ready, id::ChannelId, misc::Mentionable},
Expand Down
1 change: 1 addition & 0 deletions examples/11_create_message_builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "11_create_message_builder"
version = "0.1.0"
authors = ["my name <my@email.address>"]
edition = "2018"

[dependencies]
serenity = { path = "../../" }
8 changes: 3 additions & 5 deletions examples/11_create_message_builder/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate serenity;

use std::env;

use serenity::{
Expand All @@ -16,17 +14,17 @@ impl EventHandler for Handler {
// 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 a footer.
let msg = msg.channel_id.send_message(|mut m| {
let msg = msg.channel_id.send_message(|m| {
m.content("Hello, World!");
m.embed(|mut e| {
m.embed(|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),
]);
e.field("This is the third field", "This is not an inline field", false);
e.footer(|mut f| {
e.footer(|f| {
f.text("This is a footer");

f
Expand Down
12 changes: 6 additions & 6 deletions src/builder/create_embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
//! [here]: https://discordapp.com/developers/docs/resources/channel#embed-object
use chrono::{DateTime, TimeZone};
use internal::prelude::*;
use model::channel::Embed;
use crate::internal::prelude::*;
use crate::model::channel::Embed;
use serde_json::Value;
use std::{
default::Default,
fmt::Display
};
use utils::{self, VecMap};
use crate::utils::{self, VecMap};

#[cfg(feature = "utils")]
use utils::Colour;
use crate::utils::Colour;

/// A builder to create a fake [`Embed`] object, for use with the
/// [`ChannelId::send_message`] and [`ExecuteWebhook::embeds`] methods.
Expand Down Expand Up @@ -526,10 +526,10 @@ impl<'a, Tz: TimeZone> From<&'a DateTime<Tz>> for Timestamp

#[cfg(test)]
mod test {
use model::channel::{Embed, EmbedField, EmbedFooter, EmbedImage, EmbedVideo};
use crate::model::channel::{Embed, EmbedField, EmbedFooter, EmbedImage, EmbedVideo};
use serde_json::Value;
use super::CreateEmbed;
use utils::{self, Colour};
use crate::utils::{self, Colour};

#[test]
fn test_from_embed() {
Expand Down
4 changes: 2 additions & 2 deletions src/builder/create_invite.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use internal::prelude::*;
use crate::internal::prelude::*;
use serde_json::Value;
use std::default::Default;
use utils::VecMap;
use crate::utils::VecMap;

/// A builder to create a [`RichInvite`] for use via [`GuildChannel::create_invite`].
///
Expand Down
8 changes: 4 additions & 4 deletions src/builder/create_message.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use internal::prelude::*;
use http::AttachmentType;
use model::channel::ReactionType;
use crate::internal::prelude::*;
use crate::http::AttachmentType;
use crate::model::channel::ReactionType;
use std::fmt::Display;
use super::CreateEmbed;
use utils::{self, VecMap};
use crate::utils::{self, VecMap};

/// A builder to specify the contents of an [`http::send_message`] request,
/// primarily meant for use through [`ChannelId::send_message`].
Expand Down
6 changes: 3 additions & 3 deletions src/builder/edit_channel.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use internal::prelude::*;
use utils::VecMap;
use model::id::ChannelId;
use crate::internal::prelude::*;
use crate::utils::VecMap;
use crate::model::id::ChannelId;

/// A builder to edit a [`GuildChannel`] for use via [`GuildChannel::edit`]
///
Expand Down
6 changes: 3 additions & 3 deletions src/builder/edit_guild.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use internal::prelude::*;
use model::prelude::*;
use utils::VecMap;
use crate::internal::prelude::*;
use crate::model::prelude::*;
use crate::utils::VecMap;

/// A builder to optionally edit certain fields of a [`Guild`]. This is meant
/// for usage with [`Guild::edit`].
Expand Down
6 changes: 3 additions & 3 deletions src/builder/edit_member.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use internal::prelude::*;
use model::id::{ChannelId, RoleId};
use utils::VecMap;
use crate::internal::prelude::*;
use crate::model::id::{ChannelId, RoleId};
use crate::utils::VecMap;

/// A builder which edits the properties of a [`Member`], to be used in
/// conjunction with [`Member::edit`].
Expand Down
Loading

0 comments on commit 21518c8

Please sign in to comment.