Skip to main content

af_slack/block/
text.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
7use af_core::prelude::*;
8
9/// A text object.
10#[derive(Debug, Serialize)]
11pub struct Text<'a> {
12  /// The kind of text object.
13  #[serde(rename = "type")]
14  pub kind: TextKind,
15  /// The text value.
16  pub text: Cow<'a, str>,
17}
18
19impl<'a> Text<'a> {
20  /// Returns a mrkdwn text object.
21  pub fn mrkdwn(text: impl Into<Cow<'a, str>>) -> Self {
22    Self { kind: TextKind::Mrkdwn, text: text.into() }
23  }
24
25  /// Returns a plain text object.
26  pub fn plain(text: impl Into<Cow<'a, str>>) -> Self {
27    Self { kind: TextKind::Plain, text: text.into() }
28  }
29}
30
31/// One of the possible kinds of text object.
32#[derive(Debug, Serialize)]
33pub enum TextKind {
34  /// A mrkdown text object.
35  #[serde(rename = "mrkdwn")]
36  Mrkdwn,
37  /// A plain text object.
38  #[serde(rename = "plain_text")]
39  Plain,
40}