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:
textortext_plainortext_mdvalue
§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>
impl<T, V, U> OptBuilder<'static, T, V, U>
Sourcepub fn new() -> OptBuilderInit<'static>
pub fn new() -> OptBuilderInit<'static>
Construct a new OptBuilder
Source§impl<'a, T, V, U> OptBuilder<'a, T, V, U>
impl<'a, T, V, U> OptBuilder<'a, T, V, U>
Sourcepub fn value<S>(self, value: S) -> OptBuilder<'a, T, Set<value>, U>
pub fn value<S>(self, value: S) -> OptBuilder<'a, T, Set<value>, U>
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.
Sourcepub fn desc<S>(self, desc: S) -> OptBuilder<'a, T, V, U>
pub fn desc<S>(self, desc: S) -> OptBuilder<'a, T, V, U>
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>
impl<'a, V, U> OptBuilder<'a, RequiredMethodNotCalled<text>, V, U>
Sourcepub fn child<T: Into<Text>>(
self,
text: T,
) -> OptBuilder<'a, Set<(text, T)>, V, U>
Available on crate feature blox only.
pub fn child<T: Into<Text>>( self, text: T, ) -> OptBuilder<'a, Set<(text, T)>, V, U>
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)Sourcepub fn text<Txt>(self, text: Txt) -> OptBuilder<'a, Set<(text, Txt)>, V, U>
pub fn text<Txt>(self, text: Txt) -> OptBuilder<'a, Set<(text, Txt)>, V, U>
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.
Sourcepub fn text_plain<Txt>(
self,
text: Txt,
) -> OptBuilder<'a, Set<(text, Plain)>, V, U>
pub fn text_plain<Txt>( self, text: Txt, ) -> OptBuilder<'a, Set<(text, Plain)>, V, U>
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.
Sourcepub fn text_md<Txt>(
self,
text: Txt,
) -> OptBuilder<'a, Set<(text, Mrkdwn)>, V, U>
pub fn text_md<Txt>( self, text: Txt, ) -> OptBuilder<'a, Set<(text, Mrkdwn)>, V, U>
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>
impl<'a, V, U> OptBuilder<'a, Set<(text, Plain)>, V, U>
Sourcepub fn url<S>(self, url: S) -> OptBuilder<'a, Set<(text, Plain)>, V, Set<url>>
pub fn url<S>(self, url: S) -> OptBuilder<'a, Set<(text, Plain)>, V, Set<url>>
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§impl<'a> OptBuilder<'a, Set<(text, Plain)>, Set<value>, Set<url>>
impl<'a> OptBuilder<'a, Set<(text, Plain)>, Set<value>, Set<url>>
Sourcepub fn build(self) -> Opt<'a, Plain, AllowUrl>
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>>
impl<'a, T: Into<Text>> OptBuilder<'a, Set<(text, T)>, Set<value>, OptionalMethodNotCalled<url>>
Sourcepub fn build(self) -> Opt<'a, T, NoUrl>
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();