Struct slack_blocks::elems::button::Button[][src]

pub struct Button<'a> { /* fields omitted */ }
Expand description

Button

slack api docs 🔗

Works with block types:

An interactive component that inserts a button. The button can be a trigger for anything from opening a simple link to starting a complex workflow.

To use interactive components, you will need to make some changes to prepare your app.

Read our guide to enabling interactivity 🔗.

Implementations

impl<'a> Button<'a>[src]

pub fn builder() -> ButtonBuilderInit<'a>[src]

Build a button!

see build::ButtonBuilder for example.

pub fn from_text_and_action_id(
    text: impl Into<Plain>,
    action_id: impl Into<Cow<'a, str>>
) -> Self
[src]

👎 Deprecated since 0.17.3:

use Button::builder instead

Create a Button from a text label and ID for your app to be able to identify what was pressed.

Arguments

  • text - A text object 🔗 that defines the button’s text. Can only be of type: plain_text. Maximum length for the text in this field is 75 characters.
  • action_id - An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action 🔗. Should be unique among all other action_ids used elsewhere by your app. Maximum length for this field is 255 characters.

Example

use slack_blocks::{blocks::{Actions, Block},
                   elems};

let btn = elems::Button::from_text_and_action_id("Button", "123");
let actions_block: Block =
  Actions::from_action_elements(vec![btn.into()]).into();
// < send block to slack's API >

pub fn with_url(self, url: impl Into<Cow<'a, str>>) -> Self[src]

👎 Deprecated since 0.17.3:

use Button::builder instead

Configure a button to be a link to an external URL to load in the user’s browser on click.

Arguments

Example

use slack_blocks::blocks::{Block, Actions};
use slack_blocks::elems;

let btn = elems::Button::from_text_and_action_id("Go to cheese!", "123").with_url("https://www.cheese.com/");
let actions_block: Block = Actions::from_action_elements(vec![btn.into()]).into();
// < send block to slack's API >

pub fn with_value(self, value: impl Into<Cow<'a, str>>) -> Self[src]

👎 Deprecated since 0.17.3:

use Button::builder instead

Add a meaningful value to send back to your app when this button is clicked.

Arguments

  • value - The value to send along with the interaction payload. Maximum length for this field is 2000 characters.

Example

use slack_blocks::blocks::{Block, Actions};
use slack_blocks::elems;

let btn = elems::Button::from_text_and_action_id("Click me!", "123")
    .with_value("<something that will help your system better act on the interaction>");
let actions_block: Block = Actions::from_action_elements(vec![btn.into()]).into();
// < send block to slack's API >

pub fn with_style(self, style: Style) -> Self[src]

👎 Deprecated since 0.17.3:

use Button::builder instead

Decorates buttons with alternative visual color schemes. Use this option with restraint.

If this method is not called, the default button style will be used.

Arguments

  • style - The style to decorate your button with.

Example

use slack_blocks::blocks::{Block, Actions};
use slack_blocks::elems::{Button, button::Style};

let confirm_btn = Button::from_text_and_action_id("Confirm!", "123")
    .with_style(Style::Primary);

let deny_btn = Button::from_text_and_action_id("Deny!", "123")
    .with_style(Style::Danger);

let actions_block: Block = Actions::from_action_elements(
    vec![confirm_btn.into(), deny_btn.into()]
).into();
// < send block to slack's API >

pub fn validate(&self) -> Result<(), ValidationErrors>[src]

Validate that this Button element agrees with Slack’s model requirements

Errors

  • If from_text_and_action_id was called with an action_id longer than 255 chars
  • If from_text_and_action_id was called with text longer than 75 chars
  • If with_url was called with url longer than 3000 chars
  • If with_value was called with url longer than 2000 chars

Example

use slack_blocks::elems::Button;

let long_string = std::iter::repeat(' ').take(256).collect::<String>();

let btn = Button::from_text_and_action_id("Button", long_string);

assert_eq!(true, matches!(btn.validate(), Err(_)));

Trait Implementations

impl<'a> Clone for Button<'a>[src]

fn clone(&self) -> Button<'a>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'a> Debug for Button<'a>[src]

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

Formats the value using the given formatter. Read more

impl<'de, 'a> Deserialize<'de> for Button<'a>[src]

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
    __D: Deserializer<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl<'a> From<Button<'a>> for SupportedElement<'a>[src]

fn from(src: Button<'a>) -> Self[src]

Performs the conversion.

impl<'a> From<Button<'a>> for BlockElement<'a>[src]

fn from(src: Button<'a>) -> Self[src]

Performs the conversion.

impl<'a> Hash for Button<'a>[src]

fn hash<__H: Hasher>(&self, state: &mut __H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

impl<'a> PartialEq<Button<'a>> for Button<'a>[src]

fn eq(&self, other: &Button<'a>) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Button<'a>) -> bool[src]

This method tests for !=.

impl<'a> Serialize for Button<'a>[src]

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

Serialize this value into the given Serde serializer. Read more

impl<'a> Validate for Button<'a>[src]

impl<'a> StructuralPartialEq for Button<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Button<'a>

impl<'a> Send for Button<'a>

impl<'a> Sync for Button<'a>

impl<'a> Unpin for Button<'a>

impl<'a> UnwindSafe for Button<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]