aboutsummaryrefslogtreecommitdiff
path: root/src/utils/message_builder.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-18 11:00:45 -0800
committerAustin Hellyer <[email protected]>2016-11-18 11:00:45 -0800
commitcf128b1a10d0636c8b4b5233d46b068cfe665688 (patch)
treef36b1cd08d00cec69a76eb10c493ab3b86d61678 /src/utils/message_builder.rs
parentFeature macros should use else as block separator (diff)
downloadserenity-cf128b1a10d0636c8b4b5233d46b068cfe665688.tar.xz
serenity-cf128b1a10d0636c8b4b5233d46b068cfe665688.zip
A bit of docs
Diffstat (limited to 'src/utils/message_builder.rs')
-rw-r--r--src/utils/message_builder.rs77
1 files changed, 69 insertions, 8 deletions
diff --git a/src/utils/message_builder.rs b/src/utils/message_builder.rs
index 7ba7717..a9a88ae 100644
--- a/src/utils/message_builder.rs
+++ b/src/utils/message_builder.rs
@@ -5,11 +5,12 @@ use ::model::{ChannelId, Emoji, Mentionable, RoleId, UserId};
/// The Message Builder is an ergonomic utility to easily build a message,
/// by adding text and mentioning mentionable structs.
///
-/// The finalized value can be accessed via `.build()` or the inner value.
+/// The finalized value can be accessed via [`build`] or the inner value.
///
/// # Examples
///
-/// Build a message, mentioning a user and an emoji:
+/// Build a message, mentioning a [`user`] and an [`emoji`], and retrieving the
+/// value:
///
/// ```rust,ignore
/// use serenity::utils::MessageBuilder;
@@ -23,6 +24,10 @@ use ::model::{ChannelId, Emoji, Mentionable, RoleId, UserId};
/// .mention(emoji)
/// .build();
/// ```
+///
+/// [`build`]: #method.build
+/// [`emoji`]: #method.emoji
+/// [`user`]: #method.user
pub struct MessageBuilder(pub String);
impl MessageBuilder {
@@ -31,20 +36,46 @@ impl MessageBuilder {
MessageBuilder::default()
}
- /// Pulls the inner value out of the builder. This is equivilant to simply
- /// retrieving the value.
+ /// Pulls the inner value out of the builder.
+ ///
+ /// # Examples
+ ///
+ /// This is equivilant to simply retrieving the tuple struct's first value:
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let content = MessageBuilder::new().push("test").0;
+ ///
+ /// assert_eq!(content, "test");
+ /// ```
pub fn build(self) -> String {
self.0
}
- /// Mentions the channel in the built message.
+ /// Mentions the [`PublicChannel`] in the built message.
+ ///
+ /// This accepts anything that converts _into_ a [`ChannelId`]. Refer to
+ /// `ChannelId`'s documentation for more information.
+ ///
+ /// Refer to `ChannelId`'s [Display implementation] for more information on
+ /// how this is formatted.
+ ///
+ /// [`ChannelId`]: ../model/struct.ChannelId.html
+ /// [`PublicChannel`]: ../model/struct.PublicChannel.html
+ /// [Display implementation]: ../model/struct.ChannelId.html#method.fmt-1
pub fn channel<C: Into<ChannelId>>(mut self, channel: C) -> Self {
self.0.push_str(&format!("{}", channel.into()));
self
}
- /// Uses and displays the given emoji in the built message.
+ /// Displays the given emoji in the built message.
+ ///
+ /// Refer to `Emoji`s [Display implementation] for more information on how
+ /// this is formatted.
+ ///
+ /// [Display implementation]: ../model/struct.Emoji.html#method.fmt
pub fn emoji(mut self, emoji: Emoji) -> Self {
self.0.push_str(&format!("{}", emoji));
@@ -65,6 +96,16 @@ impl MessageBuilder {
/// Note that this does not mutate either the given data or the internal
/// message content in anyway prior to appending the given content to the
/// internal message.
+ ///
+ /// # Examples
+ ///
+ /// ```rust
+ /// use serenity::utils::MessageBuilder;
+ ///
+ /// let message = MessageBuilder::new().push("test");
+ ///
+ /// assert_eq!(message.push("ing").0, "testing");
+ /// ```
pub fn push(mut self, content: &str) -> Self {
self.0.push_str(content);
@@ -72,14 +113,34 @@ impl MessageBuilder {
}
- /// Mentions the role in the built message.
+ /// Mentions the [`Role`] in the built message.
+ ///
+ /// This accepts anything that converts _into_ a [`RoleId`]. Refer to
+ /// `RoleId`'s documentation for more information.
+ ///
+ /// Refer to `RoleId`'s [Display implementation] for more information on how
+ /// this is formatted.
+ ///
+ /// [`Role`]: ../model/struct.Role.html
+ /// [`RoleId`]: ../model/struct.RoleId.html
+ /// [Display implementation]: ../model/struct.RoleId.html#method.fmt-1
pub fn role<R: Into<RoleId>>(mut self, role: R) -> Self {
self.0.push_str(&format!("{}", role.into()));
self
}
- /// Mentions the user in the built message.
+ /// Mentions the [`User`] in the built message.
+ ///
+ /// This accepts anything that converts _into_ a [`UserId`]. Refer to
+ /// `UserId`'s documentation for more information.
+ ///
+ /// Refer to `UserId`'s [Display implementation] for more information on how
+ /// this is formatted.
+ ///
+ /// [`User`]: ../model/struct.User.html
+ /// [`UserId`]: ../model/struct.UserId.html
+ /// [Display implementation]: ../model/struct.UserId.html#method.fmt-1
pub fn user<U: Into<UserId>>(mut self, user: U) -> Self {
self.0.push_str(&format!("{}", user.into()));