Skip to main content

Component

Struct Component 

Source
pub struct Component(/* private fields */);
Expand description

A JSON text component, built field by field.

use rift_plugin::text::Component;

let invite = Component::text("Alex invited you. ")
    .extra(Component::text("[Accept]").color("green").bold().run_command("/party accept Alex"));
assert_eq!(
    serde_json::Value::from(invite),
    serde_json::json!({
        "text": "Alex invited you. ",
        "extra": [{
            "text": "[Accept]", "color": "green", "bold": true,
            "click_event": {"action": "run_command", "command": "/party accept Alex"},
        }],
    })
);

Implementations§

Source§

impl Component

Source

pub fn text(text: impl Into<String>) -> Self

A component showing text.

Source

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

A colour name such as red or #ff8800.

Source

pub fn bold(self) -> Self

Bold text.

Source

pub fn italic(self) -> Self

Italic text.

Source

pub fn underlined(self) -> Self

Underlined text.

Source

pub fn strikethrough(self) -> Self

Struck-through text.

Source

pub fn obfuscated(self) -> Self

Obfuscated (scrambling) text.

Source

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

A click runs command (with its leading /) as the player.

Source

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

A click puts command into the player’s chat box.

Source

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

A click opens url (http or https) after a confirmation.

Source

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

A click copies text to the clipboard.

Source

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

Hover text shown as written.

Source

pub fn hover(self, component: impl Into<Value>) -> Self

Hover text as a component, such as another Component or a mini object.

Source

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

Text inserted into the chat box on shift-click.

Source

pub fn extra(self, child: impl Into<Value>) -> Self

Appends a child: a Component, an authoring object or a string shown as written. Children inherit this component’s style.

Source

pub fn field(self, key: impl Into<String>, value: impl Into<Value>) -> Self

Sets any other field, such as font, shadow_color or "italic": false.

Source

pub fn to_value(&self) -> Value

The component as JSON.

Trait Implementations§

Source§

impl Clone for Component

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 Debug for Component

Source§

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

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

impl Display for Component

Source§

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

The JSON text.

Source§

impl From<Component> for Value

Source§

fn from(builder: Component) -> Value

Converts to this type from the input type.
Source§

impl PartialEq for Component

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 Component

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Resource for T
where T: 'static,

Source§

type Rep = Option<T>

The type which is actually stored in-memory for this resource. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.