twilight_util::builder::embed

Struct EmbedBuilder

Source
pub struct EmbedBuilder(/* private fields */);
Available on crate feature builder only.
Expand description

Create an [Embed] with a builder.

§Examples

Build a simple embed:

use twilight_util::builder::embed::{EmbedBuilder, EmbedFieldBuilder};

let embed = EmbedBuilder::new()
    .description("Here's a list of reasons why Twilight is the best pony:")
    .field(EmbedFieldBuilder::new("Wings", "She has wings.").inline())
    .field(
        EmbedFieldBuilder::new("Horn", "She can do magic, and she's really good at it.")
            .inline(),
    )
    .validate()?
    .build();

Build an embed with an image:

use twilight_util::builder::embed::{EmbedBuilder, ImageSource};

let embed = EmbedBuilder::new()
    .description("Here's a cool image of Twilight Sparkle")
    .image(ImageSource::attachment("bestpony.png")?)
    .validate()?
    .build();

Implementations§

Source§

impl EmbedBuilder

Source

pub fn new() -> Self

Create a new embed builder.

Source

pub fn build(self) -> Embed

Build this into an embed.

Source

pub fn validate(self) -> Result<Self, EmbedValidationError>

Ensure the embed is valid.

§Errors

Refer to the documentation of [twilight_validate::embed::embed] for possible errors.

Source

pub fn author(self, author: impl Into<EmbedAuthor>) -> Self

Set the author.

§Examples

Create an embed author:

use twilight_util::builder::embed::{EmbedAuthorBuilder, EmbedBuilder};

let author = EmbedAuthorBuilder::new("Twilight")
    .url("https://github.com/twilight-rs/twilight")
    .build();

let embed = EmbedBuilder::new().author(author).validate()?.build();
Source

pub const fn color(self, color: u32) -> Self

Set the color.

This must be a valid hexadecimal RGB value. Refer to COLOR_MAXIMUM for the maximum acceptable value.

§Examples

Set the color of an embed to 0xfd69b3:

use twilight_util::builder::embed::EmbedBuilder;

let embed = EmbedBuilder::new()
    .color(0xfd_69_b3)
    .description("a description")
    .validate()?
    .build();
Source

pub fn description(self, description: impl Into<String>) -> Self

Set the description.

Refer to DESCRIPTION_LENGTH for the maximum number of UTF-16 code points that can be in a description.

§Examples
use twilight_util::builder::embed::EmbedBuilder;

let embed = EmbedBuilder::new()
    .description("this is an embed")
    .validate()?
    .build();
Source

pub fn field(self, field: impl Into<EmbedField>) -> Self

Add a field to the embed.

§Examples
use twilight_util::builder::embed::{EmbedBuilder, EmbedFieldBuilder};

let embed = EmbedBuilder::new()
    .description("this is an embed")
    .field(EmbedFieldBuilder::new("a field", "and its value"))
    .validate()?
    .build();
Source

pub fn footer(self, footer: impl Into<EmbedFooter>) -> Self

Set the footer of the embed.

§Examples
use twilight_util::builder::embed::{EmbedBuilder, EmbedFooterBuilder};

let embed = EmbedBuilder::new()
    .description("this is an embed")
    .footer(EmbedFooterBuilder::new("a footer"))
    .validate()?
    .build();
Source

pub fn image(self, image_source: ImageSource) -> Self

Set the image.

§Examples

Set the image source to a URL:

use twilight_util::builder::embed::{EmbedBuilder, EmbedFooterBuilder, ImageSource};

let source =
    ImageSource::url("https://raw.githubusercontent.com/twilight-rs/twilight/main/logo.png")?;
let embed = EmbedBuilder::new()
    .footer(EmbedFooterBuilder::new("twilight"))
    .image(source)
    .validate()?
    .build();
Source

pub fn thumbnail(self, image_source: ImageSource) -> Self

Add a thumbnail.

§Examples

Set the thumbnail to an image attachment with the filename "twilight.png":

use twilight_util::builder::embed::{EmbedBuilder, ImageSource};

let embed = EmbedBuilder::new()
    .description("a picture of twilight")
    .thumbnail(ImageSource::attachment("twilight.png")?)
    .validate()?
    .build();
Source

pub const fn timestamp(self, timestamp: Timestamp) -> Self

Set the ISO 8601 timestamp.

Source

pub fn title(self, title: impl Into<String>) -> Self

Set the title.

Refer to TITLE_LENGTH for the maximum number of UTF-16 code points that can be in a title.

§Examples

Set the title to “twilight”:

use twilight_util::builder::embed::EmbedBuilder;

let embed = EmbedBuilder::new()
    .title("twilight")
    .url("https://github.com/twilight-rs/twilight")
    .validate()?
    .build();
Source

pub fn url(self, url: impl Into<String>) -> Self

Set the URL.

§Examples

Set the URL to twilight’s repository:

use twilight_util::builder::embed::{EmbedBuilder, EmbedFooterBuilder};

let embed = EmbedBuilder::new()
    .description("twilight's repository")
    .url("https://github.com/twilight-rs/twilight")
    .validate()?
    .build();

Trait Implementations§

Source§

impl Clone for EmbedBuilder

Source§

fn clone(&self) -> EmbedBuilder

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EmbedBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EmbedBuilder

Source§

fn default() -> Self

Create an embed builder with a default embed.

All embeds have a “rich” type.

Source§

impl From<Embed> for EmbedBuilder

Source§

fn from(value: Embed) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for EmbedBuilder

Source§

fn eq(&self, other: &EmbedBuilder) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<EmbedBuilder> for Embed

Source§

fn try_from(builder: EmbedBuilder) -> Result<Self, Self::Error>

Convert an embed builder into an embed, validating its contents.

This is equivalent to calling EmbedBuilder::validate, then EmbedBuilder::build.

Source§

type Error = EmbedValidationError

The type returned in the event of a conversion error.
Source§

impl Eq for EmbedBuilder

Source§

impl StructuralPartialEq for EmbedBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.