Skip to main content

Theme

Struct Theme 

Source
pub struct Theme {
    pub primary: u32,
    pub success: u32,
    pub warning: u32,
    pub error: u32,
    pub info: u32,
    pub author: Option<Branding>,
    pub footer: Option<Branding>,
}
Expand description

A bot’s colors and branding, set on an App with #[app(.., theme = THEME)] and read with ctx.theme(). An App listed in another uses its own Theme, if set, and fills in the rest from the outer one; errors are rendered with the outermost App’s.

use composure::command::Theme;

const THEME: Theme = Theme::new()
    .with_primary(0xf5c2e7)
    .with_author("Composure", Some("https://example.com/icon.png"))
    .with_footer("composure-rs", None);

let saved = THEME.success("Saved");
assert_eq!(saved.color, Some(THEME.success));

Message responses (and deferred edits) of a themed App are filled in where unset: every embed gets primary, the first the author, the last the footer; top-level Containers get primary as accent color. Errors become an error-colored embed. Wrap a response in Unthemed to send it as is. Messages sent through REST are never changed: build them with the helpers.

See the Themes chapter of the guide.

Fields§

§primary: u32

Embeds without a semantic color, auto-filled embeds and container accents (0xRRGGBB)

§success: u32§warning: u32§error: u32

Theme::error embeds, and the error messages users see when a handler fails

§info: u32

Theme::info embeds

§author: Option<Branding>

Set on the first embed of a themed message, and on every helper’s embed

§footer: Option<Branding>

Set on the last embed of a themed message, and on every helper’s embed

Implementations§

Source§

impl Theme

Source

pub const DEFAULT: Theme

Discord’s palette, no branding. What ctx.theme() returns when none is set.

Source

pub const fn new() -> Self

Theme::DEFAULT, to customize with the builder methods

Source

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

Sets primary: the default color of embeds and container accents

Source

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

Sets success

Source

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

Sets warning

Source

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

Sets error, also used for handler error messages

Source

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

Sets info

Source

pub const fn with_author( self, name: &'static str, icon_url: Option<&'static str>, ) -> Self

Author shown at the top of themed embeds

Footer shown at the bottom of themed embeds

Source

pub fn embed(&self) -> Embed

An empty embed with the primary color and the branding

Source

pub fn success(&self, message: impl Into<String>) -> Embed

A branded embed with message in the success color

Source

pub fn warning(&self, message: impl Into<String>) -> Embed

A branded embed with message in the warning color

Source

pub fn error(&self, message: impl Into<String>) -> Embed

A branded embed with message in the error color

Source

pub fn info(&self, message: impl Into<String>) -> Embed

A branded embed with message in the info color

Source

pub fn apply(&self, response: &mut InteractionResponse)

Fills unset colors and branding on a message response: the primary color on every embed and as accent of top-level containers, the author on the first embed, the footer on the last. Other responses and Unthemed messages are left as is.

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Theme

Source§

impl Debug for Theme

Source§

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

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

impl Default for Theme

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Theme

Source§

impl PartialEq for Theme

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Theme

Auto Trait Implementations§

§

impl Freeze for Theme

§

impl RefUnwindSafe for Theme

§

impl Send for Theme

§

impl Sync for Theme

§

impl Unpin for Theme

§

impl UnsafeUnpin for Theme

§

impl UnwindSafe for Theme

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, dest: *mut u8)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoAttr<Option<T>> for T

Source§

fn into_attr(self) -> Option<T>

The field value
Source§

impl<T> IntoAttr<T> for T

Source§

fn into_attr(self) -> T

The field value
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more