Skip to content

Commit

Permalink
Reformat... again (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
arqunis committed Jan 18, 2021
1 parent 602b0c2 commit 5e378e7
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ impl<'a> Future for ClientBuilder<'a> {
/// receive, acting as a "ping-pong" bot is simple:
///
/// ```no_run
/// use serenity::prelude::*;
/// use serenity::model::prelude::*;
/// use serenity::prelude::*;
/// use serenity::Client;
///
/// struct Handler;
Expand Down
9 changes: 6 additions & 3 deletions src/model/channel/reaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,14 @@ impl<'a> TryFrom<&'a str> for ReactionType {
/// rest of the library:
///
/// ```rust
/// use serenity::model::channel::ReactionType;
/// use std::convert::TryInto;
/// use std::fmt::Debug;
///
/// use serenity::model::channel::ReactionType;
///
/// fn foo<R: TryInto<ReactionType>>(bar: R)
/// where R::Error: Debug
/// where
/// R::Error: Debug,
/// {
/// println!("{:?}", bar.try_into().unwrap());
/// }
Expand All @@ -500,9 +502,10 @@ impl<'a> TryFrom<&'a str> for ReactionType {
/// Creating a `ReactionType` from a custom emoji argument in the following format:
///
/// ```rust
/// use std::convert::TryFrom;
///
/// use serenity::model::channel::ReactionType;
/// use serenity::model::id::EmojiId;
/// use std::convert::TryFrom;
///
/// let emoji_string = "<:customemoji:600404340292059257>";
/// let reaction = ReactionType::try_from(emoji_string).unwrap();
Expand Down
32 changes: 12 additions & 20 deletions src/model/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ pub trait Mentionable {
/// to_channel: GuildChannel,
/// rules_channel: ChannelId,
/// ) -> Result<(), Error> {
/// to_channel.id.send_message(
/// ctx,
/// |m| m.content(format_args!(
/// "Hi {member}, welcome to the server! \
/// to_channel
/// .id
/// .send_message(ctx, |m| {
/// m.content(format_args!(
/// "Hi {member}, welcome to the server! \
/// Please refer to {rules} for our code of conduct, \
/// and enjoy your stay.",
/// member = member.mention(),
/// rules = rules_channel.mention(),
/// )),
/// ).await?;
/// member = member.mention(),
/// rules = rules_channel.mention(),
/// ))
/// })
/// .await?;
/// Ok(())
/// }
/// # }
Expand All @@ -59,12 +61,7 @@ pub trait Mentionable {
/// let role: RoleId = 3.into();
/// assert_eq!(
/// "<@1> <#2> <@&3>",
/// format!(
/// "{} {} {}",
/// user.mention(),
/// channel.mention(),
/// role.mention(),
/// ),
/// format!("{} {} {}", user.mention(), channel.mention(), role.mention(),),
/// )
/// ```
fn mention(&self) -> Mention;
Expand All @@ -89,12 +86,7 @@ pub trait Mentionable {
/// let role: RoleId = 3.into();
/// assert_eq!(
/// "<@1> <#2> <@&3>",
/// format!(
/// "{} {} {}",
/// Mention::from(user),
/// Mention::from(channel),
/// Mention::from(role),
/// ),
/// format!("{} {} {}", Mention::from(user), Mention::from(channel), Mention::from(role),),
/// )
/// ```
pub struct Mention(MentionableImpl);
Expand Down
105 changes: 48 additions & 57 deletions src/utils/message_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ impl MessageBuilder {
///
/// let channel_id = ChannelId(81384788765712384);
///
/// let content = MessageBuilder::new()
/// .channel(channel_id)
/// .push("!")
/// .build();
/// let content = MessageBuilder::new().channel(channel_id).push("!").build();
///
/// assert_eq!(content, "<#81384788765712384>!");
/// ```
Expand Down Expand Up @@ -126,10 +123,7 @@ impl MessageBuilder {
///
/// let channel_id = ChannelId(81384788765712384);
///
/// let content = MessageBuilder::new()
/// .push("The channel is: ")
/// .channel(channel_id)
/// .build();
/// let content = MessageBuilder::new().push("The channel is: ").channel(channel_id).build();
///
/// assert_eq!(content, "The channel is: <#81384788765712384>");
/// ```
Expand Down Expand Up @@ -176,11 +170,7 @@ impl MessageBuilder {
/// # "roles": Vec::<Role>::new(),
/// # })).unwrap();
///
/// let message = MessageBuilder::new()
/// .push("foo ")
/// .emoji(&emoji)
/// .push(".")
/// .build();
/// let message = MessageBuilder::new().push("foo ").emoji(&emoji).push(".").build();
///
/// assert_eq!(message, "foo <:smugAnimeFace:302516740095606785>.");
/// # }
Expand Down Expand Up @@ -214,7 +204,13 @@ impl MessageBuilder {
/// let mut message = MessageBuilder::new();
/// message.push("test");
///
/// assert_eq!({ message.push("ing"); message.build() }, "testing");
/// assert_eq!(
/// {
/// message.push("ing");
/// message.build()
/// },
/// "testing"
/// );
/// ```
#[inline]
pub fn push<D: I>(&mut self, content: D) -> &mut Self {
Expand Down Expand Up @@ -299,9 +295,7 @@ impl MessageBuilder {
/// .push(".")
/// .build();
///
/// let expected = format!("The setting `{}` for this server is `{}`.",
/// key,
/// value);
/// let expected = format!("The setting `{}` for this server is `{}`.", key, value);
///
/// assert_eq!(content, expected);
/// ```
Expand Down Expand Up @@ -678,9 +672,8 @@ impl MessageBuilder {
/// ```rust
/// use serenity::utils::MessageBuilder;
///
/// let content = MessageBuilder::new().push_line_safe("Hello @everyone")
/// .push("How are you?")
/// .build();
/// let content =
/// MessageBuilder::new().push_line_safe("Hello @everyone").push("How are you?").build();
///
/// assert_eq!(content, "Hello @\u{200B}everyone\nHow are you?");
/// ```
Expand All @@ -700,9 +693,8 @@ impl MessageBuilder {
/// ```rust
/// use serenity::utils::MessageBuilder;
///
/// let content = MessageBuilder::new()
/// .push_mono_line_safe("`hello @everyone`")
/// .push("world").build();
/// let content =
/// MessageBuilder::new().push_mono_line_safe("`hello @everyone`").push("world").build();
///
/// assert_eq!(content, "`'hello @\u{200B}everyone'`\nworld");
/// ```
Expand All @@ -722,9 +714,8 @@ impl MessageBuilder {
/// ```rust
/// use serenity::utils::MessageBuilder;
///
/// let content = MessageBuilder::new()
/// .push_italic_line_safe("@everyone")
/// .push("Isn't a mention.").build();
/// let content =
/// MessageBuilder::new().push_italic_line_safe("@everyone").push("Isn't a mention.").build();
///
/// assert_eq!(content, "_@\u{200B}everyone_\nIsn't a mention.");
/// ```
Expand All @@ -744,9 +735,8 @@ impl MessageBuilder {
/// ```rust
/// use serenity::utils::MessageBuilder;
///
/// let content = MessageBuilder::new()
/// .push_bold_line_safe("@everyone")
/// .push("Isn't a mention.").build();
/// let content =
/// MessageBuilder::new().push_bold_line_safe("@everyone").push("Isn't a mention.").build();
///
/// assert_eq!(content, "**@\u{200B}everyone**\nIsn't a mention.");
/// ```
Expand All @@ -767,8 +757,9 @@ impl MessageBuilder {
/// use serenity::utils::MessageBuilder;
///
/// let content = MessageBuilder::new()
/// .push_underline_line_safe("@everyone")
/// .push("Isn't a mention.").build();
/// .push_underline_line_safe("@everyone")
/// .push("Isn't a mention.")
/// .build();
///
/// assert_eq!(content, "__@\u{200B}everyone__\nIsn't a mention.");
/// ```
Expand All @@ -789,9 +780,8 @@ impl MessageBuilder {
/// ```rust
/// use serenity::utils::MessageBuilder;
///
/// let content = MessageBuilder::new()
/// .push_strike_line_safe("@everyone")
/// .push("Isn't a mention.").build();
/// let content =
/// MessageBuilder::new().push_strike_line_safe("@everyone").push("Isn't a mention.").build();
///
/// assert_eq!(content, "~~@\u{200B}everyone~~\nIsn't a mention.");
/// ```
Expand All @@ -812,9 +802,8 @@ impl MessageBuilder {
/// ```rust
/// use serenity::utils::MessageBuilder;
///
/// let content = MessageBuilder::new()
/// .push_spoiler_line_safe("@everyone")
/// .push("Isn't a mention.").build();
/// let content =
/// MessageBuilder::new().push_spoiler_line_safe("@everyone").push("Isn't a mention.").build();
///
/// assert_eq!(content, "||@\u{200B}everyone||\nIsn't a mention.");
/// ```
Expand All @@ -835,9 +824,8 @@ impl MessageBuilder {
/// ```rust
/// use serenity::utils::MessageBuilder;
///
/// let content = MessageBuilder::new()
/// .push_quote_line_safe("@everyone")
/// .push("Isn't a mention.").build();
/// let content =
/// MessageBuilder::new().push_quote_line_safe("@everyone").push("Isn't a mention.").build();
///
/// assert_eq!(content, "> @\u{200B}everyone\nIsn't a mention.");
/// ```
Expand Down Expand Up @@ -919,13 +907,13 @@ impl Display for MessageBuilder {
/// ```rust
/// #[cfg(feature = "utils")]
/// {
/// use serenity::utils::{EmbedMessageBuilding, MessageBuilder};
/// use serenity::utils::{EmbedMessageBuilding, MessageBuilder};
///
/// let msg = MessageBuilder::new()
/// .push_named_link("Rust's GitHub", "https://github.com/rust-lang")
/// .build();
/// let msg = MessageBuilder::new()
/// .push_named_link("Rust's GitHub", "https://github.com/rust-lang")
/// .build();
///
/// assert_eq!(msg, "[Rust's GitHub](https://github.com/rust-lang)");
/// assert_eq!(msg, "[Rust's GitHub](https://github.com/rust-lang)");
/// }
///
/// #[cfg(not(feature = "utils"))]
Expand All @@ -944,14 +932,14 @@ pub trait EmbedMessageBuilding {
/// ```rust
/// #[cfg(feature = "utils")]
/// {
/// use serenity::utils::{EmbedMessageBuilding, MessageBuilder};
/// use serenity::utils::{EmbedMessageBuilding, MessageBuilder};
///
/// let mut msg = MessageBuilder::new();
/// msg.push("Rust's website: ");
/// msg.push_named_link("Homepage", "https://rust-lang.org");
/// let content = msg.build();
/// let mut msg = MessageBuilder::new();
/// msg.push("Rust's website: ");
/// msg.push_named_link("Homepage", "https://rust-lang.org");
/// let content = msg.build();
///
/// assert_eq!(content, "Rust's website: [Homepage](https://rust-lang.org)");
/// assert_eq!(content, "Rust's website: [Homepage](https://rust-lang.org)");
/// }
///
/// #[cfg(not(feature = "utils"))]
Expand All @@ -969,14 +957,17 @@ pub trait EmbedMessageBuilding {
/// ```rust
/// #[cfg(feature = "utils")]
/// {
/// use serenity::utils::{EmbedMessageBuilding, MessageBuilder};
/// use serenity::utils::{EmbedMessageBuilding, MessageBuilder};
///
/// let mut msg = MessageBuilder::new();
/// msg.push("A weird website name: ");
/// msg.push_named_link_safe("Try to ] break links (](", "https://rust-lang.org");
/// let content = msg.build();
/// let mut msg = MessageBuilder::new();
/// msg.push("A weird website name: ");
/// msg.push_named_link_safe("Try to ] break links (](", "https://rust-lang.org");
/// let content = msg.build();
///
/// assert_eq!(content, "A weird website name: [Try to break links ( (](https://rust-lang.org)");
/// assert_eq!(
/// content,
/// "A weird website name: [Try to break links ( (](https://rust-lang.org)"
/// );
/// }
///
/// #[cfg(not(feature = "utils"))]
Expand Down
15 changes: 4 additions & 11 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,7 @@ fn _read_image(path: &Path) -> Result<String> {
/// use serenity::utils::parse_quotes;
///
/// let command = r#""this is the first" "this is the second""#;
/// let expected = vec![
/// "this is the first".to_string(),
/// "this is the second".to_string()
/// ];
/// let expected = vec!["this is the first".to_string(), "this is the second".to_string()];
///
/// assert_eq!(parse_quotes(command), expected);
/// ```
Expand All @@ -370,9 +367,8 @@ fn _read_image(path: &Path) -> Result<String> {
/// use serenity::utils::parse_quotes;
///
/// let command = r#""this is a quoted command that doesn't have an ending quotation"#;
/// let expected = vec![
/// "this is a quoted command that doesn't have an ending quotation".to_string(),
/// ];
/// let expected =
/// vec!["this is a quoted command that doesn't have an ending quotation".to_string()];
///
/// assert_eq!(parse_quotes(command), expected);
/// ```
Expand Down Expand Up @@ -704,10 +700,7 @@ async fn clean_users(
/// #
/// # async fn run() {
/// # let cache = Cache::default();
/// use serenity::utils::{
/// content_safe,
/// ContentSafeOptions,
/// };
/// use serenity::utils::{content_safe, ContentSafeOptions};
///
/// let with_mention = "@everyone";
/// let without_mention = content_safe(&cache, &with_mention, &ContentSafeOptions::default()).await;
Expand Down

0 comments on commit 5e378e7

Please sign in to comment.