pub struct Button { /* private fields */ }
Expand description

Button element representation.

Example

use slack_messaging::blocks::elements::Button;
use serde_json::json;

let button = Button::new()
    .text("Click Me")
    .set_value("click_me_123")
    .set_action_id("button-0");

let expected = json!({
    "type": "button",
    "text": {
        "type": "plain_text",
        "text": "Click Me",
        "emoji": true
    },
    "value": "click_me_123",
    "action_id": "button-0"
});

let button_json = serde_json::to_value(button).unwrap();

assert_eq!(button_json, expected);

Implementations§

source§

impl Button

source

pub fn new() -> Self

Constructs a Button element.

use slack_messaging::blocks::elements::Button;
use serde_json::json;

let button = Button::new();

let expected = json!({
    "type": "button",
    "text": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "action_id": ""
});

let button_json = serde_json::to_value(button).unwrap();

assert_eq!(button_json, expected);
source

pub fn set_text(self, text: Text) -> Self

Sets text field.

use slack_messaging::blocks::elements::{Button, Text};
use serde_json::json;

let button = Button::new().set_text(Text::plain("Click Me"));

let expected = json!({
    "type": "button",
    "text": {
        "type": "plain_text",
        "text": "Click Me",
        "emoji": true
    },
    "action_id": ""
});

let button_json = serde_json::to_value(button).unwrap();

assert_eq!(button_json, expected);
source

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

Sets text field from string. This is a shorthand for set_text method.

use slack_messaging::blocks::elements::Button;
use serde_json::json;

let button = Button::new().text("Click Me");

let expected = json!({
    "type": "button",
    "text": {
        "type": "plain_text",
        "text": "Click Me",
        "emoji": true
    },
    "action_id": ""
});

let button_json = serde_json::to_value(button).unwrap();

assert_eq!(button_json, expected);
source

pub fn set_action_id<T: Into<String>>(self, action_id: T) -> Self

Sets action_id field.

use slack_messaging::blocks::elements::Button;
use serde_json::json;

let button = Button::new().set_action_id("click_me_123");

let expected = json!({
    "type": "button",
    "text": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "action_id": "click_me_123"
});

let button_json = serde_json::to_value(button).unwrap();

assert_eq!(button_json, expected);
source

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

Sets url field.

use slack_messaging::blocks::elements::Button;
use serde_json::json;

let button = Button::new().set_url("https://google.com");

let expected = json!({
    "type": "button",
    "text": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "action_id": "",
    "url": "https://google.com"
});

let button_json = serde_json::to_value(button).unwrap();

assert_eq!(button_json, expected);
source

pub fn set_value<T: Into<String>>(self, value: T) -> Self

Sets value field.

use slack_messaging::blocks::elements::Button;
use serde_json::json;

let button = Button::new().set_value("value-0");

let expected = json!({
    "type": "button",
    "text": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "action_id": "",
    "value": "value-0"
});

let button_json = serde_json::to_value(button).unwrap();

assert_eq!(button_json, expected);
source

pub fn set_primary(self) -> Self

Sets primary to style field.

use slack_messaging::blocks::elements::Button;
use serde_json::json;

let button = Button::new().set_primary();

let expected = json!({
    "type": "button",
    "text": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "action_id": "",
    "style": "primary"
});

let button_json = serde_json::to_value(button).unwrap();

assert_eq!(button_json, expected);
source

pub fn set_danger(self) -> Self

Sets danger to style field.

use slack_messaging::blocks::elements::Button;
use serde_json::json;

let button = Button::new().set_danger();

let expected = json!({
    "type": "button",
    "text": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "action_id": "",
    "style": "danger"
});

let button_json = serde_json::to_value(button).unwrap();

assert_eq!(button_json, expected);
source

pub fn set_confirm(self, confirm: ConfirmationDialog) -> Self

Sets confirm field with ConfirmationDialog object.

use slack_messaging::blocks::elements::{Button, ConfirmationDialog};
use serde_json::json;

let button = Button::new()
    .set_confirm(
        ConfirmationDialog::new()
            .set_title("Are you sure?")
            .set_text("Wouldn't you prefer a good game of _chess_?")
            .set_confirm("Do it")
            .set_deny("Stop, I've changed my mind!")
    );

let expected = json!({
    "type": "button",
    "text": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "action_id": "",
    "confirm": {
        "title": {
            "type": "plain_text",
            "text": "Are you sure?",
            "emoji": true
        },
        "text": {
            "type": "plain_text",
            "text": "Wouldn't you prefer a good game of _chess_?",
            "emoji": true
        },
        "confirm": {
            "type": "plain_text",
            "text": "Do it",
            "emoji": true
        },
        "deny": {
            "type": "plain_text",
            "text": "Stop, I've changed my mind!",
            "emoji": true
        }
    }
});

let button_json = serde_json::to_value(button).unwrap();

assert_eq!(button_json, expected);
source

pub fn set_accessibility_label<T: Into<String>>(self, label: T) -> Self

Sets accessibility_label field.

use slack_messaging::blocks::elements::Button;
use serde_json::json;

let button = Button::new().set_accessibility_label("Click Me");

let expected = json!({
    "type": "button",
    "text": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "action_id": "",
    "accessibility_label": "Click Me"
});

let button_json = serde_json::to_value(button).unwrap();

assert_eq!(button_json, expected);

Trait Implementations§

source§

impl Clone for Button

source§

fn clone(&self) -> Button

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 Button

source§

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

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

impl Default for Button

source§

fn default() -> Self

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

impl From<Button> for Accessory

source§

fn from(value: Button) -> Self

Converts to this type from the input type.
source§

impl From<Button> for ActionsElement

source§

fn from(value: Button) -> Self

Converts to this type from the input type.
source§

impl Serialize for Button

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.