Struct slack_blocks::compose::opt::build::OptBuilder[][src]

pub struct OptBuilder<'a, Text, Value, Url> { /* fields omitted */ }
Expand description

Option builder

Allows you to construct a Option composition object safely, with compile-time checks on required setter methods.

Required Methods

Opt::build() is only available if these methods have been called:

  • text or text_plain or text_md
  • value

Example

use std::convert::TryFrom;

use slack_blocks::{blocks::{Actions, Block},
                   compose::Opt,
                   elems::{select::Static, BlockElement}};
let langs = vec![("Rust", "rs"), ("Haskell", "hs"), ("NodeJS", "node")];

let langs =
  langs.into_iter().map(|(name, code)| {
                     Opt::builder().text_plain(name).value(code).build()
                   });

let select =
  Static::builder().placeholder("Choose your favorite programming language!")
                   .options(langs)
                   .action_id("lang_chosen")
                   .build();

let block: Block = Actions::builder().element(select).build().into();

// <send block to API>

Implementations

Construct a new OptBuilder

Set value (Required)

The string value that will be passed to your app when this option is chosen.

Maximum length for this field is 75 characters.

Set description (Optional)

A plain_text only text object 🔗 that defines a line of descriptive text shown below the text field beside the radio button.

Maximum length for the text object within this field is 75 characters.

This is supported on crate feature blox only.

Alias for text, allowing you to set the text of the option like so:

use slack_blocks::{blox::*, compose::Opt, text};

let xml = blox! {
  <option value="foo">
    <text kind=plain>"Foo"</text>
  </option>
};

let equiv = Opt::builder().value("foo")
                          .text(text::Plain::from("Foo"))
                          .build();

assert_eq!(xml, equiv)

Set text (Required)

A text object 🔗 that defines the text shown in the option on the menu. Overflow, select, and multi-select menus can only use plain_text objects, while radio buttons and checkboxes can use mrkdwn text objects.

Maximum length for the text in this field is 75 characters.

Set text (Required)

A text object 🔗 that defines the text shown in the option on the menu. Overflow, select, and multi-select menus can only use plain_text objects, while radio buttons and checkboxes can use mrkdwn text objects.

Maximum length for the text in this field is 75 characters.

Set text (Required)

A text object 🔗 that defines the text shown in the option on the menu. Overflow, select, and multi-select menus can only use plain_text objects, while radio buttons and checkboxes can use mrkdwn text objects.

Maximum length for the text in this field is 75 characters.

Set url (Optional)

The URL will be loaded in the user’s browser when the option is clicked.

Maximum length for this field is 3000 characters.

The url attribute is only available in overflow menus 🔗

If you’re using url, you’ll still receive an interaction payload 🔗 and will need to send an acknowledgement response 🔗.

Flag opt as being usable in an AllowUrl context without setting Url explicitly.

All done building, now give me a darn option!

no method name 'build' found for struct 'compose::opt::build::OptBuilder<...>'?

Make sure all required setter methods have been called. See docs for OptBuilder.

use slack_blocks::compose::Opt;

let sel = Opt::builder().build(); // Won't compile!
use slack_blocks::compose::Opt;

let opt = Opt::builder().text_plain("cheese")
                        .value("cheese")
                        .url("https://cheese.com")
                        .build();

All done building, now give me a darn option!

no method name 'build' found for struct 'compose::opt::build::OptBuilder<...>'?

Make sure all required setter methods have been called. See docs for OptBuilder.

use slack_blocks::compose::Opt;

let sel = Opt::builder().text_plain("foo")
                        .build();
/*                       ^^^^^ method not found in
                         `OptBuilder<'_, Set<(text, text::Plain)>, RequiredMethodNotCalled<value>>`
*/
use slack_blocks::compose::Opt;

let opt = Opt::builder().text_md("cheese").value("cheese").build();

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

This is supported on crate feature blox only.

Identity function

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.