Struct slack_blocks::blocks::actions::Contents [−][src]
pub struct Contents<'a> { /* fields omitted */ }Expand description
Implementations
impl<'a> Contents<'a>[src]
impl<'a> Contents<'a>[src]pub fn new() -> Self[src]
pub fn new() -> Self[src]Create an empty Actions block (shorthand for Default::default())
Example
use slack_blocks::blocks::{actions, Block}; let actions = actions::Contents::new(); let block: Block = actions.into(); // < send block to slack's API >
pub fn with_block_id(self, block_id: impl ToString) -> Self[src]
pub fn with_block_id(self, block_id: impl ToString) -> Self[src]Set the block_id for interactions on an existing actions::Contents
Arguments
block_id- A string acting as a unique identifier for a block. You can use thisblock_idwhen you receive an interaction payload to identify the source of the action 🔗. If not specified, ablock_idwill be generated. Maximum length for this field is 255 characters.
Example
use slack_blocks::blocks::{actions, Block}; let actions = actions::Contents::new().with_block_id("tally_ho"); let block: Block = actions.into(); // < send block to slack's API >
pub fn from_elements<Iter>(elements: Iter) -> Result<Self, ()> where
Iter: IntoIterator<Item = BlockElement<'a>>, [src]
pub fn from_elements<Iter>(elements: Iter) -> Result<Self, ()> where
Iter: IntoIterator<Item = BlockElement<'a>>, [src]Populate an Actions block with a collection of elems::BlockElements,
which may not be supported by Actions blocks.
If you can create a collection of actions::BlockElement,
either by creating them directly or invoking elems::BlockElement::into,
use from_action_elements.
Arguments
elements- An array of interactive element objects 🔗 For a list ofBlockElementtypes that are, seeBlockElement. There is a maximum of 5 elements in each action block.
Errors
Errors if the elems::BlockElement is one that is not supported by
Actions blocks.
For a list of BlockElement types that are supported, see ::blocks::actions::BlockElement.
Runtime Validation
only validates that the block elements are compatible with Actions,
for full runtime model validation see the validate method.
Example
use slack_blocks::{blocks::{actions, Block}, compose, elems}; let btn = elems::Button::from_text_and_action_id("Button", "123"); let actions = actions::Contents::from_elements(vec![btn.into()])?; let block: Block = actions.into(); // < send block to slack's API >
pub fn from_action_elements<Iter>(elements: Iter) -> Self where
Iter: IntoIterator<Item = BlockElement<'a>>, [src]
pub fn from_action_elements<Iter>(elements: Iter) -> Self where
Iter: IntoIterator<Item = BlockElement<'a>>, [src]Populate an Actions block with a collection of BlockElements that
are supported by Actions blocks.
This also can be called via the From<Vec<self::BlockElement>> implementation.
If you have a collection of elements that may not be supported,
see from_elements.
Arguments
elements- An array of interactive element objects 🔗 For a list ofBlockElementtypes that are supported, seeBlockElement. There is a maximum of 5 elements in each action block. Note that if you only ever want 1 item you can choose to pass itSome(element)ORstd::iter::once(element)instead of aVec, bypassing an expensive allocation. Iterator and Option implement IntoIterator 🔗.
Errors
Errors if the elems::BlockElement is one that is not supported by
Actions blocks.
Runtime Validation
only validates that the block elements are compatible with Actions,
for full runtime model validation see the validate method.
Example
use slack_blocks::{blocks::{actions, Block}, compose, elems}; let btn = elems::Button::from_text_and_action_id("Button", "123"); let actions = actions::Contents::from_action_elements(vec![btn.into()]); let block: Block = actions.into(); // < send block to slack's API >
pub fn validate(&self) -> Result<(), ValidationErrors>[src]
pub fn validate(&self) -> Result<(), ValidationErrors>[src]Validate that this Section block agrees with Slack’s model requirements
Errors
- If
with_block_idwas called with a block id longer than 255 chars - If
from_elementsorfrom_action_elementswas called with more than 5 elements.
Example
use slack_blocks::{blocks, compose}; let long_string = std::iter::repeat(' ').take(256).collect::<String>(); let block = blocks::actions ::Contents ::from_action_elements(vec![]) .with_block_id(long_string); assert!(matches!(block.validate(), Err(_)));
Trait Implementations
impl<'de, 'a> Deserialize<'de> for Contents<'a>[src]
impl<'de, 'a> Deserialize<'de> for Contents<'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<Vec<BlockElement<'a>, Global>> for Contents<'a>[src]
impl<'a> From<Vec<BlockElement<'a>, Global>> for Contents<'a>[src]fn from(src: Vec<BlockElement<'a>>) -> Self[src]
fn from(src: Vec<BlockElement<'a>>) -> Self[src]Performs the conversion.
impl<'a> TryFrom<BlockElement<'a>> for Contents<'a>[src]
impl<'a> TryFrom<BlockElement<'a>> for Contents<'a>[src]impl<'a> StructuralPartialEq for Contents<'a>[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for Contents<'a>
impl<'a> Send for Contents<'a>
impl<'a> Sync for Contents<'a>
impl<'a> Unpin for Contents<'a>
impl<'a> UnwindSafe for Contents<'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 = TThe 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>,