slack_rust/block/
block_context.rs

1//! Displays message context, which can include both images and text.
2
3use crate::block::block_elements::MixedElement;
4use serde::{Deserialize, Serialize};
5use serde_with::skip_serializing_none;
6
7/// Displays message context, which can include both images and text.  
8/// See: <https://api.slack.com/reference/block-kit/blocks#context>
9#[skip_serializing_none]
10#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
11pub struct ContextBlock {
12    pub elements: Vec<MixedElement>,
13    pub block_id: Option<String>,
14}
15
16impl ContextBlock {
17    pub fn builder(elements: Vec<MixedElement>) -> ContextBlockBuilder {
18        ContextBlockBuilder::new(elements)
19    }
20}
21
22#[derive(Debug, Default)]
23pub struct ContextBlockBuilder {
24    pub elements: Vec<MixedElement>,
25    pub block_id: Option<String>,
26}
27
28impl ContextBlockBuilder {
29    pub fn new(elements: Vec<MixedElement>) -> ContextBlockBuilder {
30        ContextBlockBuilder {
31            elements,
32            ..Default::default()
33        }
34    }
35    pub fn block_id(mut self, block_id: String) -> ContextBlockBuilder {
36        self.block_id = Some(block_id);
37        self
38    }
39    pub fn build(self) -> ContextBlock {
40        ContextBlock {
41            elements: self.elements,
42            block_id: self.block_id,
43        }
44    }
45}