af_slack/
block.rs

1// Copyright © 2021 Alexandra Frydl
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7//! Block kit.
8
9mod text;
10
11pub use self::text::Text;
12
13use af_core::prelude::*;
14
15/// Returns a Header block.
16pub fn header<'a>(text: impl Into<Cow<'a, str>>) -> Block<'a> {
17  Block::Header { text: Text::plain(text) }
18}
19
20/// Returns a Section block.
21pub fn section<'a>(text: impl Into<Cow<'a, str>>) -> Block<'a> {
22  Block::Section { text: Text::mrkdwn(text) }
23}
24
25/// A content block.
26#[derive(Debug, Serialize)]
27#[serde(rename_all = "snake_case", tag = "type")]
28pub enum Block<'a> {
29  Header { text: Text<'a> },
30  Section { text: Text<'a> },
31}
32
33impl<'a, T> From<T> for Block<'a>
34where
35  Cow<'a, str>: From<T>,
36{
37  fn from(value: T) -> Self {
38    section(value)
39  }
40}