Trait serenity::utils::EmbedMessageBuilding [−][src]
pub trait EmbedMessageBuilding {
fn push_named_link<T: I, U: I>(&mut self, name: T, url: U) -> &mut Self;
fn push_named_link_safe<T: I, U: I>(&mut self, name: T, url: U) -> &mut Self;
}
Expand description
A trait with additional functionality over the MessageBuilder
for
creating content with additional functionality available only in embeds.
Namely, this allows you to create named links via the non-escaping
Self::push_named_link
method and the escaping Self::push_named_link_safe
method.
Examples
Make a named link to Rust’s GitHub organization:
#[cfg(feature = "utils")]
{
use serenity::utils::{EmbedMessageBuilding, MessageBuilder};
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)");
}
#[cfg(not(feature = "utils"))]
{}
Required methods
fn push_named_link<T: I, U: I>(&mut self, name: T, url: U) -> &mut Self
fn push_named_link<T: I, U: I>(&mut self, name: T, url: U) -> &mut Self
Pushes a named link to a message, intended for use in embeds.
Examples
Make a simple link to Rust’s homepage for use in an embed:
#[cfg(feature = "utils")]
{
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();
assert_eq!(content, "Rust's website: [Homepage](https://rust-lang.org)");
}
#[cfg(not(feature = "utils"))]
{}
fn push_named_link_safe<T: I, U: I>(&mut self, name: T, url: U) -> &mut Self
fn push_named_link_safe<T: I, U: I>(&mut self, name: T, url: U) -> &mut Self
Pushes a named link intended for use in an embed, but with a normalized name to avoid escaping issues.
Refer to Self::push_named_link
for more information.
Examples
#[cfg(feature = "utils")]
{
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();
assert_eq!(
content,
"A weird website name: [Try to break links ( (](https://rust-lang.org)"
);
}
#[cfg(not(feature = "utils"))]
{}