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

source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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()));

Trait Implementations§

source§

impl Clone for Opt

source§

fn clone(&self) -> Opt

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Opt

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Opt

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Serialize for Opt

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Opt

§

impl Send for Opt

§

impl Sync for Opt

§

impl Unpin for Opt

§

impl UnwindSafe for Opt

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.