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 T)

🔬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.