OptBuilder

Struct OptBuilder 

Source
pub struct OptBuilder<'a, Text, Value, Url> { /* private fields */ }
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§

Source§

impl<T, V, U> OptBuilder<'static, T, V, U>

Source

pub fn new() -> OptBuilderInit<'static>

Construct a new OptBuilder

Source§

impl<'a, T, V, U> OptBuilder<'a, T, V, U>

Source

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

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.

Source

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

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.

Source§

impl<'a, V, U> OptBuilder<'a, RequiredMethodNotCalled<text>, V, U>

Source

pub fn child<T: Into<Text>>( self, text: T, ) -> OptBuilder<'a, Set<(text, T)>, V, U>

Available 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)
Source

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

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.

Source

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

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.

Source

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

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.

Source§

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

Source

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

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

Source

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

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

Source§

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

Source

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

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

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

Source

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

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§

Source§

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

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, Text, Value, Url> Freeze for OptBuilder<'a, Text, Value, Url>

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> IntoChild for T

Source§

fn into_child(self) -> Self

Available on crate feature blox only.
Identity function
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,