[−][src]Struct slack_blocks::blocks::context::Contents
Implementations
impl Contents[src]
pub fn new() -> Self[src]
Create an empty Context block (shorthand for Default::default())
Example
use slack_blocks::blocks::{Block, context}; use slack_blocks::text; let context = context::Contents::new() .with_element(text::Plain::from("my unformatted text")); let block: Block = context.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 context::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, context}; use slack_blocks::text; let text = text::Mrkdwn::from("_flavor_ *text*"); let context: Block = context::Contents::new() .with_element(text) .with_block_id("msg_id_12346") .into(); // < send block to slack's API >
pub fn with_element(self, element: impl Into<Compose>) -> Self[src]
Add a composition object to a context block.
This is chainable, and can be used to easily
populate the elements of a context block
right after invoking new.
Arguments
element- A composition object; Must be image elements or text objects. Maximum number of items is 10.
Example
use slack_blocks::blocks::{Block, context}; use slack_blocks::text; let context = context::Contents::new() .with_element(text::Plain::from("my unformatted text")); let block: Block = context.into(); // < send block to slack's API >
pub fn from_context_elements(
elements: impl IntoIterator<Item = impl Into<Compose>>
) -> Self[src]
elements: impl IntoIterator<Item = impl Into<Compose>>
) -> Self
Construct a new context::Contents from a collection of
composition objects that are may not be supported by Context
Blocks.
If you can't guarantee that a collection only contains image
or text objects, from_elements may be more ergonomic for you.
Arguments
elements- An array of composition objects; Must be image elements or text objects. Maximum number of items is 10.
Examples
use slack_blocks::blocks::{Block, context}; use slack_blocks::text; pub fn main() { let objs: Vec<text::Mrkdwn> = vec![ text::Mrkdwn::from("*s i c k*"), text::Mrkdwn::from("*t i g h t*"), ]; let context = context::Contents::from_context_elements(objs); let block: Block = context.into(); // < send block to slack's API > }
pub fn validate(&self) -> Result<(), ValidationErrors>[src]
Validate that this Context block agrees with Slack's model requirements
Errors
- If
with_block_idwas called with a block id longer than 255 chars - If
from_elements,from_context_elements, orwith_elementwas called with more than 10 objects
Example
use slack_blocks::blocks; let long_string = std::iter::repeat(' ').take(256).collect::<String>(); let block = blocks::context ::Contents ::new() .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<Compose>> for Contents[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 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>,