slack_rust/block/
block_section.rs

1//! A section is one of the most flexible blocks available
2
3use crate::block::block_elements::BlockElement;
4use crate::block::block_object::TextBlockObject;
5use serde::{Deserialize, Serialize};
6use serde_with::skip_serializing_none;
7
8/// A section is one of the most flexible blocks available.  
9/// See: <https://api.slack.com/reference/block-kit/blocks#section>
10#[skip_serializing_none]
11#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
12pub struct SectionBlock {
13    pub text: Option<TextBlockObject>,
14    pub block_id: Option<String>,
15    pub fields: Option<Vec<TextBlockObject>>,
16    pub accessory: Option<BlockElement>,
17}
18
19impl SectionBlock {
20    pub fn builder() -> SectionBlockBuilder {
21        SectionBlockBuilder::new()
22    }
23}
24
25#[derive(Debug, Default)]
26pub struct SectionBlockBuilder {
27    pub text: Option<TextBlockObject>,
28    pub block_id: Option<String>,
29    pub fields: Option<Vec<TextBlockObject>>,
30    pub accessory: Option<BlockElement>,
31}
32
33impl SectionBlockBuilder {
34    pub fn new() -> SectionBlockBuilder {
35        SectionBlockBuilder {
36            ..Default::default()
37        }
38    }
39    pub fn text(mut self, text: TextBlockObject) -> SectionBlockBuilder {
40        self.text = Some(text);
41        self
42    }
43    pub fn block_id(mut self, block_id: String) -> SectionBlockBuilder {
44        self.block_id = Some(block_id);
45        self
46    }
47    pub fn fields(mut self, fields: Vec<TextBlockObject>) -> SectionBlockBuilder {
48        self.fields = Some(fields);
49        self
50    }
51    pub fn accessory(mut self, accessory: BlockElement) -> SectionBlockBuilder {
52        self.accessory = Some(accessory);
53        self
54    }
55    pub fn build(self) -> SectionBlock {
56        SectionBlock {
57            text: self.text,
58            block_id: self.block_id,
59            fields: self.fields,
60            accessory: self.accessory,
61        }
62    }
63}