pub struct OptGroupBuilder<'a, T, U, Options, Label> { /* private fields */ }Expand description
Option Group builder
Allows you to construct a Option Group object safely, with compile-time checks on required setter methods.
§Required Methods
OptGroup::build() is only available if these methods have been called:
optionslabel
§Example
use std::convert::TryFrom;
use slack_blocks::{elems::{select::Static, BlockElement},
blocks::{Actions, Block},
compose::{Opt, OptGroup}};
#[derive(Clone, Copy, PartialEq)]
enum LangStyle {
Functional,
ObjectOriented,
SomewhereInbetween,
}
use LangStyle::*;
#[derive(Clone, Copy)]
struct Lang {
name: &'static str,
code: &'static str,
style: LangStyle,
}
impl Lang {
fn new(name: &'static str, code: &'static str, style: LangStyle) -> Self {
Self {
name,
code,
style,
}
}
}
let langs = vec![
Lang::new("Rust", "rs", SomewhereInbetween),
Lang::new("C#", "cs", ObjectOriented),
Lang::new("Haskell", "hs", Functional),
];
let langs_of_style = |needle: LangStyle| langs.iter()
.filter(|Lang {style, ..}| *style == needle)
.map(|lang| Opt::builder()
.text_plain(lang.name)
.value(lang.code)
.build()
)
.collect::<Vec<_>>();
let groups = vec![
OptGroup::builder()
.label("Functional")
.options(langs_of_style(Functional))
.build(),
OptGroup::builder()
.label("Object-Oriented")
.options(langs_of_style(ObjectOriented))
.build(),
OptGroup::builder()
.label("Somewhere Inbetween")
.options(langs_of_style(SomewhereInbetween))
.build(),
];
let select =
Static::builder().placeholder("Choose your favorite programming language!")
.option_groups(groups)
.action_id("lang_chosen")
.build();
let block: Block =
Actions::builder().element(select).build()
.into();
// <send block to API>Implementations§
Source§impl<'a, T, U, O, L> OptGroupBuilder<'a, T, U, O, L>
impl<'a, T, U, O, L> OptGroupBuilder<'a, T, U, O, L>
Sourcepub fn options<T2, U2, I>(
self,
options: I,
) -> OptGroupBuilder<'a, T2, U2, Set<options>, L>where
I: IntoIterator<Item = Opt<'a, T2, U2>>,
pub fn options<T2, U2, I>(
self,
options: I,
) -> OptGroupBuilder<'a, T2, U2, Set<options>, L>where
I: IntoIterator<Item = Opt<'a, T2, U2>>,
Set the options of this group (Required, or option)
An array of option objects 🔗 that belong to this specific group.
Maximum of 100 items.
Sourcepub fn label<S>(self, label: S) -> OptGroupBuilder<'a, T, U, O, Set<label>>
pub fn label<S>(self, label: S) -> OptGroupBuilder<'a, T, U, O, Set<label>>
A plain_text only text object 🔗 that defines
the label shown above this group of options.
Maximum length for the text in this field is 75 characters.
Source§impl<'a, T, U, L> OptGroupBuilder<'a, T, U, RequiredMethodNotCalled<options>, L>
impl<'a, T, U, L> OptGroupBuilder<'a, T, U, RequiredMethodNotCalled<options>, L>
Sourcepub fn option<T2, U2>(
self,
option: Opt<'a, T2, U2>,
) -> OptGroupBuilder<'a, T2, U2, Set<options>, L>
pub fn option<T2, U2>( self, option: Opt<'a, T2, U2>, ) -> OptGroupBuilder<'a, T2, U2, Set<options>, L>
Append an option to this group (Required, or options)
Maximum of 100 items.
Sourcepub fn child<T2, U2>(
self,
option: Opt<'a, T2, U2>,
) -> OptGroupBuilder<'a, T2, U2, Set<options>, L>
Available on crate feature blox only.
pub fn child<T2, U2>( self, option: Opt<'a, T2, U2>, ) -> OptGroupBuilder<'a, T2, U2, Set<options>, L>
blox only.XML child alias for option.
Source§impl<'a, T, U, L> OptGroupBuilder<'a, T, U, Set<options>, L>
impl<'a, T, U, L> OptGroupBuilder<'a, T, U, Set<options>, L>
Source§impl<'a, T, U> OptGroupBuilder<'a, T, U, Set<options>, Set<label>>
impl<'a, T, U> OptGroupBuilder<'a, T, U, Set<options>, Set<label>>
Sourcepub fn build(self) -> OptGroup<'a, T, U>
pub fn build(self) -> OptGroup<'a, T, U>
All done building, now give me a darn option group!
no method name 'build' found for struct 'compose::opt_group::build::OptGroupBuilder<...>'? Make sure all required setter methods have been called. See docs forOptGroupBuilder.
use slack_blocks::compose::OptGroup;
let sel = OptGroup::builder()
.build();
/* ^^^^^ method not found in
`OptGroupBuilder<'_, RequiredMethodNotCalled<options>, RequiredMethodNotCalled<value>, _>`
*/use slack_blocks::compose::{Opt, OptGroup};
let sel = OptGroup::builder().options(vec![Opt::builder().text_plain("foo")
.value("bar")
.build()])
.label("foo")
.build();