[−][src]Struct slack_blocks::blocks::actions::Contents
Implementations
impl Contents[src]
pub fn new() -> Self[src]
Create an empty Actions block (shorthand for Default::default())
Example
use slack_blocks::blocks::{Block, actions}; 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]
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::{Block, actions}; 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(
elements: impl IntoIterator<Item = BlockElement>
) -> Result<Self, ()>[src]
elements: impl IntoIterator<Item = BlockElement>
) -> Result<Self, ()>
Populate an Actions block with a collection of block_elements::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 block_elements::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 block_elements::BlockElement is one that is not supported by
Actions blocks.
For a list of BlockElement types that are, see 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::{Block, actions}; use slack_blocks::compose; use slack_blocks::block_elements; let btn = block_elements::BlockElement::Button; let actions = actions::Contents::from_elements(vec![btn])?; let block: Block = actions.into(); // < send block to slack's API >
pub fn from_action_elements(
elements: impl IntoIterator<Item = BlockElement>
) -> Self[src]
elements: impl IntoIterator<Item = BlockElement>
) -> Self
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.
Errors
Errors if the block_elements::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::{Block, actions}; use slack_blocks::compose; use slack_blocks::block_elements; let btn = actions::BlockElement::Button; let actions = actions::Contents::from_action_elements(vec![btn]); let block: Block = actions.into(); // < send block to slack's API >
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; use slack_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_eq!(true, matches!(block.validate(), Err(_)));
Trait Implementations
impl Clone for Contents[src]
impl Debug for Contents[src]
impl Default for Contents[src]
impl<'de> Deserialize<'de> for Contents[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>, [src]
__D: Deserializer<'de>,
impl From<Contents> for Block[src]
impl From<Vec<BlockElement>> for Contents[src]
fn from(elements: Vec<BlockElement>) -> Self[src]
impl Hash for Contents[src]
fn hash<__H: Hasher>(&self, state: &mut __H)[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
impl PartialEq<Contents> for Contents[src]
impl Serialize for Contents[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer, [src]
__S: Serializer,
impl StructuralPartialEq for Contents[src]
impl TryFrom<Vec<BlockElement>> for Contents[src]
type Error = ()
The type returned in the event of a conversion error.
fn try_from(elements: Vec<BlockElement>) -> Result<Self, Self::Error>[src]
impl Validate for Contents[src]
fn validate(&self) -> Result<(), ValidationErrors>[src]
Auto Trait Implementations
impl RefUnwindSafe for Contents
impl Send for Contents
impl Sync for Contents
impl Unpin for Contents
impl UnwindSafe for Contents
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>, [src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,