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

Input block representation.

Example

use slack_messaging::blocks::Input;
use slack_messaging::blocks::elements::PlainTextInput;
use serde_json::json;

let input = Input::new()
    .set_block_id("input_1")
    .label("label text")
    .set_element(
        PlainTextInput::new()
            .set_action_id("text_area_1")
            .multiline()
            .placeholder("Enter some plain text.")
    )
    .optional();

let expected = json!({
    "type": "input",
    "block_id": "input_1",
    "label": {
        "type": "plain_text",
        "text": "label text",
        "emoji": true
    },
    "element": {
        "type": "plain_text_input",
        "action_id": "text_area_1",
        "multiline": true,
        "placeholder": {
            "type": "plain_text",
            "text": "Enter some plain text.",
            "emoji": true
        }
    },
    "optional": true
});

let input_json = serde_json::to_value(input).unwrap();

assert_eq!(input_json, expected);

Implementations§

source§

impl Input

source

pub fn new() -> Self

Constructs an Input block.

use slack_messaging::blocks::Input;
use serde_json::json;

let input = Input::new();

let expected = json!({
    "type": "input",
    "label": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "element": null
});

let input_json = serde_json::to_value(input).unwrap();

assert_eq!(input_json, expected);
source

pub fn set_label(self, label: Text) -> Self

Sets label field.

use slack_messaging::blocks::Input;
use slack_messaging::blocks::elements::Text;
use serde_json::json;

let input = Input::new()
    .set_label(Text::plain("label text"));

let expected = json!({
    "type": "input",
    "label": {
        "type": "plain_text",
        "text": "label text",
        "emoji": true
    },
    "element": null
});

let input_json = serde_json::to_value(input).unwrap();

assert_eq!(input_json, expected);
source

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

Sets label field from string. This is a shorthand for set_label method.

use slack_messaging::blocks::Input;
use serde_json::json;

let input = Input::new().label("label text");

let expected = json!({
    "type": "input",
    "label": {
        "type": "plain_text",
        "text": "label text",
        "emoji": true
    },
    "element": null
});

let input_json = serde_json::to_value(input).unwrap();

assert_eq!(input_json, expected);
source

pub fn set_element<T: Into<InputElement>>(self, element: T) -> Self

Sets an object to element field. The argument is an any object that can transform into the enum InputElement.

use slack_messaging::blocks::Input;
use slack_messaging::blocks::elements::PlainTextInput;
use serde_json::json;

let input = Input::new()
    .set_element(
        PlainTextInput::new().set_action_id("input_1")
    );

let expected = json!({
    "type": "input",
    "label": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "element": {
        "type": "plain_text_input",
        "action_id": "input_1"
    },
});

let input_json = serde_json::to_value(input).unwrap();

assert_eq!(input_json, expected);
source

pub fn set_dispatch_action(self, dispatch_action: bool) -> Self

Sets dispatch_action field.

use slack_messaging::blocks::Input;
use serde_json::json;

let input = Input::new()
    .set_dispatch_action(true);

let expected = json!({
    "type": "input",
    "label": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "element": null,
    "dispatch_action": true
});

let input_json = serde_json::to_value(input).unwrap();

assert_eq!(input_json, expected);
source

pub fn dispatch_action(self) -> Self

Sets true to dispatch_action field.

use slack_messaging::blocks::Input;
use serde_json::json;

let input = Input::new().dispatch_action();

let expected = json!({
    "type": "input",
    "label": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "element": null,
    "dispatch_action": true
});

let input_json = serde_json::to_value(input).unwrap();

assert_eq!(input_json, expected);
source

pub fn set_block_id<T: Into<String>>(self, block_id: T) -> Self

Sets block_id field.

use slack_messaging::blocks::Input;
use serde_json::json;

let input = Input::new().set_block_id("input_1");

let expected = json!({
    "type": "input",
    "label": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "element": null,
    "block_id": "input_1"
});

let input_json = serde_json::to_value(input).unwrap();

assert_eq!(input_json, expected);
source

pub fn set_hint(self, hint: Text) -> Self

Sets hint field.

use slack_messaging::blocks::Input;
use slack_messaging::blocks::elements::Text;
use serde_json::json;

let input = Input::new()
    .set_hint(Text::plain("Some hints for input"));

let expected = json!({
    "type": "input",
    "label": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "element": null,
    "hint": {
        "type": "plain_text",
        "text": "Some hints for input",
        "emoji": true
    },
});

let input_json = serde_json::to_value(input).unwrap();

assert_eq!(input_json, expected);
source

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

Sets hint field from string. This is a shorthand for set_hint method.

use slack_messaging::blocks::Input;
use serde_json::json;

let input = Input::new().hint("Some hints for input");

let expected = json!({
    "type": "input",
    "label": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "element": null,
    "hint": {
        "type": "plain_text",
        "text": "Some hints for input",
        "emoji": true
    },
});

let input_json = serde_json::to_value(input).unwrap();

assert_eq!(input_json, expected);
source

pub fn set_optional(self, optional: bool) -> Self

Sets optional field.

use slack_messaging::blocks::Input;
use serde_json::json;

let input = Input::new().set_optional(true);

let expected = json!({
    "type": "input",
    "label": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "element": null,
    "optional": true
});

let input_json = serde_json::to_value(input).unwrap();

assert_eq!(input_json, expected);
source

pub fn optional(self) -> Self

Sets true to optional field.

use slack_messaging::blocks::Input;
use serde_json::json;

let input = Input::new().optional();

let expected = json!({
    "type": "input",
    "label": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "element": null,
    "optional": true
});

let input_json = serde_json::to_value(input).unwrap();

assert_eq!(input_json, expected);
source

pub fn required(self) -> Self

Sets false to optional field.

use slack_messaging::blocks::Input;
use serde_json::json;

let input = Input::new().required();

let expected = json!({
    "type": "input",
    "label": {
        "type": "plain_text",
        "text": "",
        "emoji": true
    },
    "element": null,
    "optional": false
});

let input_json = serde_json::to_value(input).unwrap();

assert_eq!(input_json, expected);

Trait Implementations§

source§

impl Clone for Input

source§

fn clone(&self) -> Input

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 Input

source§

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

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

impl Default for Input

source§

fn default() -> Self

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

impl From<Input> for Block

source§

fn from(value: Input) -> Self

Converts to this type from the input type.
source§

impl Serialize for Input

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 Input

§

impl Send for Input

§

impl Sync for Input

§

impl Unpin for Input

§

impl UnwindSafe for Input

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.