pub struct ConfirmationDialog { /* private fields */ }
Expand description

Confirmation dialog object representation.

Example

use slack_messaging::blocks::elements::ConfirmationDialog;
use serde_json::json;

let confirm = ConfirmationDialog::new()
    .set_title("Are you sure?")
    .set_text("Wouldn't you prefer a good game of _chess_?")
    .set_confirm("Do it")
    .set_deny("Stop, I've changed my mind!");

let expected = json!({
    "title": {
        "type": "plain_text",
        "text": "Are you sure?",
        "emoji": true
    },
    "text": {
        "type": "plain_text",
        "text": "Wouldn't you prefer a good game of _chess_?",
        "emoji": true
    },
    "confirm": {
        "type": "plain_text",
        "text": "Do it",
        "emoji": true
    },
    "deny": {
        "type": "plain_text",
        "text": "Stop, I've changed my mind!",
        "emoji": true
    }
});

let confirm_json = serde_json::to_value(confirm).unwrap();

assert_eq!(confirm_json, expected);

Implementations§

source§

impl ConfirmationDialog

source

pub fn new() -> Self

Constructs a Confirmation dialog object with empty values.

use slack_messaging::blocks::elements::ConfirmationDialog;
use serde_json::{json, Value};

let confirm = ConfirmationDialog::new();

let confirm_json = serde_json::to_value(confirm).unwrap();

assert_eq!(confirm_json["title"]["text"], Value::String("".into()));
assert_eq!(confirm_json["text"]["text"], Value::String("".into()));
assert_eq!(confirm_json["confirm"]["text"], Value::String("".into()));
assert_eq!(confirm_json["deny"]["text"], Value::String("".into()));
assert_eq!(confirm_json["style"], Value::Null);
source

pub fn set_title<T: Into<String>>(self, title: T) -> Self

Sets title field with plain_text object.

use slack_messaging::blocks::elements::ConfirmationDialog;
use serde_json::{json, Value};

let confirm = ConfirmationDialog::new()
    .set_title("Are you sure?");

let confirm_json = serde_json::to_value(confirm).unwrap();

assert_eq!(confirm_json["title"]["text"], Value::String("Are you sure?".into()));
source

pub fn set_text<T: Into<String>>(self, text: T) -> Self

Sets text field with plain_text object.

use slack_messaging::blocks::elements::ConfirmationDialog;
use serde_json::{json, Value};

let confirm = ConfirmationDialog::new()
    .set_text("Wouldn't you prefer a good game of _chess_?");

let confirm_json = serde_json::to_value(confirm).unwrap();

assert_eq!(confirm_json["text"]["text"], Value::String("Wouldn't you prefer a good game of _chess_?".into()));
source

pub fn set_confirm<T: Into<String>>(self, confirm: T) -> Self

Sets confirm field with plain_text object.

use slack_messaging::blocks::elements::ConfirmationDialog;
use serde_json::{json, Value};

let confirm = ConfirmationDialog::new()
    .set_confirm("Do it");

let confirm_json = serde_json::to_value(confirm).unwrap();

assert_eq!(confirm_json["confirm"]["text"], Value::String("Do it".into()));
source

pub fn set_deny<T: Into<String>>(self, deny: T) -> Self

Sets deny field with plain_text object.

use slack_messaging::blocks::elements::ConfirmationDialog;
use serde_json::{json, Value};

let confirm = ConfirmationDialog::new()
    .set_deny("Stop, I've changed my mind!");

let confirm_json = serde_json::to_value(confirm).unwrap();

assert_eq!(confirm_json["deny"]["text"], Value::String("Stop, I've changed my mind!".into()));
source

pub fn set_primary(self) -> Self

Sets style field as “primary”.

use slack_messaging::blocks::elements::ConfirmationDialog;
use serde_json::{json, Value};

let confirm = ConfirmationDialog::new().set_primary();

let confirm_json = serde_json::to_value(confirm).unwrap();

assert_eq!(confirm_json["style"], Value::String("primary".into()));
source

pub fn set_danger(self) -> Self

Sets style field as “danger”.

use slack_messaging::blocks::elements::ConfirmationDialog;
use serde_json::{json, Value};

let confirm = ConfirmationDialog::new().set_danger();

let confirm_json = serde_json::to_value(confirm).unwrap();

assert_eq!(confirm_json["style"], Value::String("danger".into()));

Trait Implementations§

source§

impl Clone for ConfirmationDialog

source§

fn clone(&self) -> ConfirmationDialog

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 ConfirmationDialog

source§

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

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

impl Default for ConfirmationDialog

source§

fn default() -> Self

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

impl Serialize for ConfirmationDialog

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§

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.