diff options
| author | Austin Hellyer <[email protected]> | 2016-11-13 08:22:24 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-13 08:22:24 -0800 |
| commit | f633d1c9603079f584f4f715b308b33c0750ad3a (patch) | |
| tree | f77bc0b630731676be880b11c24b90cffef8c537 /src/utils/builder/create_embed.rs | |
| parent | Don't overflow on message length check (diff) | |
| download | serenity-f633d1c9603079f584f4f715b308b33c0750ad3a.tar.xz serenity-f633d1c9603079f584f4f715b308b33c0750ad3a.zip | |
Move the builders to the utils
The builders aren't a large enough portion of the library to deserve
their own root-level module, so move them to the `utils` module.
Additionally, split them into separate files, as the library will be
receiving more builders and the single-file pattern was getting rather
large.
Diffstat (limited to 'src/utils/builder/create_embed.rs')
| -rw-r--r-- | src/utils/builder/create_embed.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/utils/builder/create_embed.rs b/src/utils/builder/create_embed.rs new file mode 100644 index 0000000..1abfb4e --- /dev/null +++ b/src/utils/builder/create_embed.rs @@ -0,0 +1,42 @@ +use serde_json::builder::ObjectBuilder; +use std::default::Default; + +/// A builder to create a fake [`Embed`] object, for use with the +/// [`ExecuteWebhook::embeds`] method. +/// +/// [`Embed`]: ../model/struct.Embed.html +/// [`ExecuteWebhook::embeds`]: struct.ExecuteWebhook.html#method.embeds +pub struct CreateEmbed(pub ObjectBuilder); + +impl CreateEmbed { + /// Set the colour of the left-hand side of the embed. + pub fn colour(self, colour: u64) -> Self { + CreateEmbed(self.0.insert("color", colour)) + } + + /// Set the description. + pub fn description(self, description: &str) -> Self { + CreateEmbed(self.0.insert("description", description)) + } + + /// Set the timestamp. + pub fn timestamp(self, timestamp: &str) -> Self { + CreateEmbed(self.0.insert("timestamp", timestamp)) + } + + /// Set the title. + pub fn title(self, title: &str) -> Self { + CreateEmbed(self.0.insert("title", title)) + } + + /// Set the URL. + pub fn url(self, url: &str) -> Self { + CreateEmbed(self.0.insert("url", url)) + } +} + +impl Default for CreateEmbed { + fn default() -> CreateEmbed { + CreateEmbed(ObjectBuilder::new()) + } +} |