Struct slack_messaging::blocks::elements::Opt
source · pub struct Opt { /* private fields */ }Expand description
Option object representation.
Example
use slack_messaging::blocks::elements::{Opt, Text};
use serde_json::json;
let option = Opt::new()
.set_text(Text::plain("Maru"))
.set_value("maru");
let expected = json!({
"text": {
"type": "plain_text",
"text": "Maru",
"emoji": true
},
"value": "maru"
});
let option_json = serde_json::to_value(option).unwrap();
assert_eq!(option_json, expected);Implementations§
source§impl Opt
impl Opt
sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a Option object with empty values.
use slack_messaging::blocks::elements::Opt;
use serde_json::{json, Value};
let option = Opt::new();
let option_json = serde_json::to_value(option).unwrap();
assert_eq!(option_json["text"]["text"], Value::String("".into()));
assert_eq!(option_json["value"], Value::String("".into()));
assert_eq!(option_json["description"], Value::Null);
assert_eq!(option_json["url"], Value::Null);sourcepub fn plain<T: Into<String>>(text: T) -> Self
pub fn plain<T: Into<String>>(text: T) -> Self
Constructs a Option object with plain_text object.
use slack_messaging::blocks::elements::Opt;
use serde_json::json;
let option = Opt::plain("This is a plain text.");
let expected = json!({
"text": {
"type": "plain_text",
"text": "This is a plain text.",
"emoji": true
},
"value": ""
});
let option_json = serde_json::to_value(option).unwrap();
assert_eq!(option_json, expected);sourcepub fn mrkdwn<T: Into<String>>(text: T) -> Self
pub fn mrkdwn<T: Into<String>>(text: T) -> Self
Constructs a Option object with mrkdwn object.
use slack_messaging::blocks::elements::Opt;
use serde_json::json;
let option = Opt::mrkdwn("This is a ~plain~markdown text.");
let expected = json!({
"text": {
"type": "mrkdwn",
"text": "This is a ~plain~markdown text."
},
"value": ""
});
let option_json = serde_json::to_value(option).unwrap();
assert_eq!(option_json, expected);sourcepub fn set_text(self, text: Text) -> Self
pub fn set_text(self, text: Text) -> Self
Sets text field.
use slack_messaging::blocks::elements::{Opt, Text};
use serde_json::json;
let option = Opt::new()
.set_text(Text::plain("This is a plain text."));
let expected = json!({
"text": {
"type": "plain_text",
"text": "This is a plain text.",
"emoji": true
},
"value": ""
});
let option_json = serde_json::to_value(option).unwrap();
assert_eq!(option_json, expected);sourcepub fn set_value<T: Into<String>>(self, value: T) -> Self
pub fn set_value<T: Into<String>>(self, value: T) -> Self
Sets text field.
use slack_messaging::blocks::elements::Opt;
use serde_json::json;
let option = Opt::new().set_value("valueeeeeee");
let expected = json!({
"text": {
"type": "plain_text",
"text": "",
"emoji": true
},
"value": "valueeeeeee"
});
let option_json = serde_json::to_value(option).unwrap();
assert_eq!(option_json, expected);sourcepub fn set_description<T: Into<String>>(self, description: T) -> Self
pub fn set_description<T: Into<String>>(self, description: T) -> Self
Sets description field with plain_text object.
use slack_messaging::blocks::elements::Opt;
use serde_json::json;
let option = Opt::new().set_description("This is a description.");
let expected = json!({
"text": {
"type": "plain_text",
"text": "",
"emoji": true
},
"value": "",
"description": {
"type": "plain_text",
"text": "This is a description.",
"emoji": true
}
});
let option_json = serde_json::to_value(option).unwrap();
assert_eq!(option_json, expected);sourcepub fn set_url<T: Into<String>>(self, url: T) -> Self
pub fn set_url<T: Into<String>>(self, url: T) -> Self
Sets url field.
use slack_messaging::blocks::elements::Opt;
use serde_json::{json, Value};
let option = Opt::new().set_url("https://google.com");
let option_json = serde_json::to_value(option).unwrap();
assert_eq!(option_json["url"], Value::String("https://google.com".into()));