Struct slack_blocks::compose::opt_group::build::OptGroupBuilder[][src]

pub struct OptGroupBuilder<'a, T, U, Options, Label> { /* fields omitted */ }
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: BlockElement =
  Static::builder().placeholder("Choose your favorite programming language!")
                   .option_groups(groups)
                   .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<'a, T, U, O, L> OptGroupBuilder<'a, T, U, O, L>[src]

pub fn new() -> Self[src]

Construct a new OptGroupBuilder

pub fn options<T2, U2, I>(
    self,
    options: I
) -> OptGroupBuilder<'a, T2, U2, Set<options>, L> where
    I: IntoIterator<Item = Opt<'a, T2, U2>>, 
[src]

Set the options of this group (Required)

An array of option objects 🔗 that belong to this specific group.

Maximum of 100 items.

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

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.

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

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

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

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

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

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

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

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

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

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