OptGroupBuilder

Struct OptGroupBuilder 

Source
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:

  • options
  • label

§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>

Source

pub fn new() -> Self

Construct a new OptGroupBuilder

Source

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.

Source

pub fn label<S>(self, label: S) -> OptGroupBuilder<'a, T, U, O, Set<label>>
where S: Into<Plain>,

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>

Source

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.

Source

pub fn child<T2, U2>( self, option: Opt<'a, T2, U2>, ) -> OptGroupBuilder<'a, T2, U2, Set<options>, L>

Available on crate feature blox only.

XML child alias for option.

Source§

impl<'a, T, U, L> OptGroupBuilder<'a, T, U, Set<options>, L>

Source

pub fn option(self, option: Opt<'a, T, U>) -> Self

Append an option to this group (Required, or options)

Maximum of 100 items.

Source

pub fn child(self, option: Opt<'a, T, U>) -> Self

Available on crate feature blox only.

XML child alias for option.

Source§

impl<'a, T, U> OptGroupBuilder<'a, T, U, Set<options>, Set<label>>

Source

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 for OptGroupBuilder.

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

Trait Implementations§

Source§

impl<'a, T: Debug, U: Debug, Options: Debug, Label: Debug> Debug for OptGroupBuilder<'a, T, U, Options, Label>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T, U, Options, Label> Freeze for OptGroupBuilder<'a, T, U, Options, Label>

§

impl<'a, T, U, Options, Label> RefUnwindSafe for OptGroupBuilder<'a, T, U, Options, Label>
where Options: RefUnwindSafe, Label: RefUnwindSafe, T: RefUnwindSafe, U: RefUnwindSafe,

§

impl<'a, T, U, Options, Label> Send for OptGroupBuilder<'a, T, U, Options, Label>
where Options: Send, Label: Send, T: Send, U: Send,

§

impl<'a, T, U, Options, Label> Sync for OptGroupBuilder<'a, T, U, Options, Label>
where Options: Sync, Label: Sync, T: Sync, U: Sync,

§

impl<'a, T, U, Options, Label> Unpin for OptGroupBuilder<'a, T, U, Options, Label>
where Options: Unpin, Label: Unpin, T: Unpin, U: Unpin,

§

impl<'a, T, U, Options, Label> UnwindSafe for OptGroupBuilder<'a, T, U, Options, Label>
where Options: UnwindSafe, Label: UnwindSafe, T: UnwindSafe, U: 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,