CheckboxesBuilder

Struct CheckboxesBuilder 

Source
pub struct CheckboxesBuilder<'a, A, O> { /* private fields */ }
Expand description

Checkbox group builder

Allows you to construct safely, with compile-time checks on required setter methods.

§Required Methods

CheckboxesBuilder::build() is only available if these methods have been called:

  • action_id
  • options

§Example

use std::convert::TryFrom;

use slack_blocks::{blocks::{Actions, Block},
                   compose::Opt,
                   elems::{BlockElement, Checkboxes}};

mod usa {
  pub struct State {
    pub name: String,
    pub abbrev: String,
  }

  pub fn arizona() -> State {
    State { name: String::from("Arizona"),
            abbrev: String::from("AZ") }
  }

  pub fn get_states() -> Vec<State> {
    // ...
  }
}

let state_opt = |state: usa::State| {
  Opt::builder().text_plain(state.name)
                .value(state.abbrev)
                .build()
};

let states: Vec<Opt<_, _>> =
  usa::get_states().into_iter().map(state_opt).collect();

let boxes =
  Checkboxes::builder().action_id("state_picker")
                       .options(states)
                       .initial_options(vec![state_opt(usa::arizona())])
                       .build();

let block: Block = Actions::builder().element(boxes).build().into();

// <send block to slack API>

Implementations§

Source§

impl<'a, A, O> CheckboxesBuilder<'a, A, O>

Source

pub fn new() -> Self

Create a new builder

Source

pub fn action_id<S>( self, action_id: S, ) -> CheckboxesBuilder<'a, Set<action_id>, O>
where S: Into<Cow<'a, str>>,

Set action_id (Optional)

An identifier for the action triggered when the checkbox group is changed.

You can use this when you receive an interaction payload to identify the source of the action 🔗.

Should be unique among all other action_ids in the containing block.

Maximum length for this field is 255 characters.

Source

pub fn child<T: Into<Text>>( self, option: Opt<'a, T, NoUrl>, ) -> CheckboxesBuilder<'a, A, Set<options>>

Available on crate feature blox only.

Append an option to options

Source

pub fn options<T: Into<Text>>( self, options: Vec<Opt<'a, T, NoUrl>>, ) -> CheckboxesBuilder<'a, A, Set<options>>

Set options (Required)

An array of option objects 🔗.

A maximum of 10 options are allowed.

Source

pub fn option<T: Into<Text>>( self, option: Opt<'a, T, NoUrl>, ) -> CheckboxesBuilder<'a, A, Set<options>>

Append an option to options

Source

pub fn initial_options<T: Into<Text>>( self, options: Vec<Opt<'a, T, NoUrl>>, ) -> Self

Set initial_options (Optional)

An array of option objects 🔗 that exactly matches one or more of the options within options.

These options will be selected when the checkbox group initially loads.

Source

pub fn confirm(self, confirm: Confirm) -> Self

Set confirm (Optional)

A confirm object 🔗 that defines an optional confirmation dialog that appears after clicking one of the checkboxes in this element.

Source§

impl<'a> CheckboxesBuilder<'a, Set<action_id>, Set<options>>

Source

pub fn build(self) -> Checkboxes<'a>

All done building, now give me a darn checkbox group!

no method name 'build' found for struct 'CheckboxesBuilder<...>'? Make sure all required setter methods have been called. See docs for CheckboxesBuilder.

use slack_blocks::elems::Checkboxes;

let foo = Checkboxes::builder().build(); // Won't compile!
use slack_blocks::{compose::Opt, elems::Checkboxes};

let foo = Checkboxes::builder().action_id("foo")
                               .options(vec![Opt::builder().text_plain("foo")
                                                           .value("bar")
                                                           .build()])
                               .build();

Trait Implementations§

Source§

impl<'a, A: Debug, O: Debug> Debug for CheckboxesBuilder<'a, A, O>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, A, O> Freeze for CheckboxesBuilder<'a, A, O>

§

impl<'a, A, O> RefUnwindSafe for CheckboxesBuilder<'a, A, O>

§

impl<'a, A, O> Send for CheckboxesBuilder<'a, A, O>
where A: Send, O: Send,

§

impl<'a, A, O> Sync for CheckboxesBuilder<'a, A, O>
where A: Sync, O: Sync,

§

impl<'a, A, O> Unpin for CheckboxesBuilder<'a, A, O>
where A: Unpin, O: Unpin,

§

impl<'a, A, O> UnwindSafe for CheckboxesBuilder<'a, A, O>
where A: UnwindSafe, O: 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,