Struct slack_blocks::elems::button::Button [−][src]
pub struct Button<'a> { /* fields omitted */ }
Expand description
Button
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]
impl<'a> Button<'a>
[src]pub fn builder() -> ButtonBuilderInit<'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
pub fn from_text_and_action_id(
text: impl Into<Plain>,
action_id: impl Into<Cow<'a, str>>
) -> Self
[src]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 otheraction_id
s 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
pub fn with_url(self, url: impl Into<Cow<'a, str>>) -> Self
[src]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
url
- A URL to load in the user’s browser when the button is clicked. Maximum length for this field is 3000 characters. If you’re using url, you’ll still receive an interaction payload 🔗 and will need to send an acknowledgement response 🔗.
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
pub fn with_value(self, value: impl Into<Cow<'a, str>>) -> Self
[src]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
pub fn with_style(self, style: Style) -> Self
[src]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]
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<'de, 'a> Deserialize<'de> for Button<'a>
[src]
impl<'de, 'a> Deserialize<'de> for Button<'a>
[src]fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[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]
impl<'a> From<Button<'a>> for SupportedElement<'a>
[src]impl<'a> From<Button<'a>> for BlockElement<'a>
[src]
impl<'a> From<Button<'a>> for BlockElement<'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> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
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]
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> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,