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: BlockElement =
  Static::builder().placeholder("Choose your favorite programming language!")
                   .options(langs)
                   .action_id("lang_chosen")
                   .build()
                   .into();

let block: Block =
  Actions::try_from(select).expect("actions supports select elements")
                           .into();

// <send block to API>

Implementations

impl<T, V, U> OptBuilder<'static, T, V, U>[src]

pub fn new() -> OptBuilderInit<'static>[src]

Construct a new OptBuilder

impl<'a, T, V, U> OptBuilder<'a, T, V, U>[src]

pub fn value<S>(self, value: S) -> OptBuilder<'a, T, Set<value>, U> where
    S: Into<Cow<'a, str>>, 
[src]

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.

pub fn desc<S>(self, desc: S) -> OptBuilder<'a, T, V, U> where
    S: Into<Plain>, 
[src]

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.

impl<'a, T, V, U> OptBuilder<'a, RequiredMethodNotCalled<T>, V, U>[src]

pub fn text_plain<Txt>(
    self,
    text: Txt
) -> OptBuilder<'a, Set<(text, Plain)>, V, U> where
    Txt: Into<Plain>, 
[src]

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.

pub fn text_md<Txt>(
    self,
    text: Txt
) -> OptBuilder<'a, Set<(text, Mrkdwn)>, V, U> where
    Txt: Into<Mrkdwn>, 
[src]

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.

pub fn text<Txt>(self, text: Txt) -> OptBuilder<'a, Set<(text, Txt)>, V, U> where
    Txt: Into<Text>, 
[src]

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.

impl<'a, V, U> OptBuilder<'a, Set<(text, Plain)>, V, U>[src]

pub fn url<S>(self, url: S) -> OptBuilder<'a, Set<(text, Plain)>, V, Set<url>> where
    S: Into<Cow<'a, str>>, 
[src]

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 🔗.

pub fn no_url(self) -> OptBuilder<'a, Set<(text, Plain)>, V, Set<url>>[src]

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

impl<'a> OptBuilder<'a, Set<(text, Plain)>, Set<value>, Set<url>>[src]

pub fn build(self) -> Opt<'a, Plain, AllowUrl>[src]

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

impl<'a, T: Into<Text>> OptBuilder<'a, Set<(text, T)>, Set<value>, OptionalMethodNotCalled<url>>[src]

pub fn build(self) -> Opt<'a, T, NoUrl>[src]

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

impl<'a, Text: Debug, Value: Debug, Url: Debug> Debug for OptBuilder<'a, Text, Value, Url>[src]

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<'a, Text, Value, Url> RefUnwindSafe for OptBuilder<'a, Text, Value, Url> where
    Text: RefUnwindSafe,
    Url: RefUnwindSafe,
    Value: RefUnwindSafe

impl<'a, Text, Value, Url> Send for OptBuilder<'a, Text, Value, Url> where
    Text: Send,
    Url: Send,
    Value: Send

impl<'a, Text, Value, Url> Sync for OptBuilder<'a, Text, Value, Url> where
    Text: Sync,
    Url: Sync,
    Value: Sync

impl<'a, Text, Value, Url> Unpin for OptBuilder<'a, Text, Value, Url> where
    Text: Unpin,
    Url: Unpin,
    Value: Unpin

impl<'a, Text, Value, Url> UnwindSafe for OptBuilder<'a, Text, Value, Url> where
    Text: UnwindSafe,
    Url: UnwindSafe,
    Value: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.