SectionBuilder

Struct SectionBuilder 

Source
pub struct SectionBuilder<'a, Text> { /* private fields */ }
Expand description

Build an Section block

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

§Required Methods

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

  • text or field(s), both may be called.

§Example

use slack_blocks::{blocks::Section,
                   elems::Image,
                   text,
                   text::ToSlackPlaintext};

let block =
  Section::builder().text("foo".plaintext())
                    .field("bar".plaintext())
                    .field("baz".plaintext())
                    // alternatively:
                    .fields(vec!["bar".plaintext(),
                                 "baz".plaintext()]
                                 .into_iter()
                                 .map(text::Text::from)
                    )
                    .accessory(Image::builder().image_url("foo.png")
                                               .alt_text("pic of foo")
                                               .build())
                    .build();

Implementations§

Source§

impl<'a, E> SectionBuilder<'a, E>

Source

pub fn new() -> Self

Create a new SectionBuilder

Source

pub fn accessory<B>(self, acc: B) -> Self
where B: Into<BlockElement<'a>>,

Set accessory (Optional)

Source

pub fn text<T>(self, text: T) -> SectionBuilder<'a, Set<text>>
where T: Into<Text>,

Add text (Required: this or field(s))

The text for the block, in the form of a text object 🔗.

Maximum length for the text in this field is 3000 characters.

Source

pub fn fields<I>(self, fields: I) -> SectionBuilder<'a, Set<text>>
where I: IntoIterator<Item = Text>,

Set fields (Required: this or text)

A collection of text objects 🔗.

Any text objects included with fields will be rendered in a compact format that allows for 2 columns of side-by-side text.

Maximum number of items is 10.

Maximum length for the text in each item is 2000 characters.

Source

pub fn field<T>(self, text: T) -> SectionBuilder<'a, Set<text>>
where T: Into<Text>,

Append a single field to fields.

Source

pub fn child<T>(self, text: T) -> SectionBuilder<'a, Set<text>>
where T: Into<Text>,

Available on crate feature blox only.

XML macro children, appends fields to the Section.

To set text, use the text attribute.

use slack_blocks::{blocks::Section, blox::*, text, text::ToSlackPlaintext};

let xml = blox! {
  <section_block text={"Section".plaintext()}>
    <text kind=plain>"Foo"</text>
    <text kind=plain>"Bar"</text>
  </section_block>
};

let equiv = Section::builder().text("Section".plaintext())
                              .field("Foo".plaintext())
                              .field("Bar".plaintext())
                              .build();

assert_eq!(xml, equiv);
Source

pub fn block_id<S>(self, block_id: S) -> Self
where S: Into<Cow<'a, str>>,

Set block_id (Optional)

A string acting as a unique identifier for a block.

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

If not specified, a block_id will be generated.

Maximum length for this field is 255 characters.

Source§

impl<'a> SectionBuilder<'a, Set<text>>

Source

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

All done building, now give me a darn actions block!

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

use slack_blocks::blocks::Section;

let foo = Section::builder().build(); // Won't compile!
use slack_blocks::{blocks::Section,
                   compose::text::ToSlackPlaintext,
                   elems::Image};

let block =
  Section::builder().text("foo".plaintext())
                    .accessory(Image::builder().image_url("foo.png")
                                               .alt_text("pic of foo")
                                               .build())
                    .build();

Trait Implementations§

Source§

impl<'a, Text: Debug> Debug for SectionBuilder<'a, Text>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, Text> Freeze for SectionBuilder<'a, Text>

§

impl<'a, Text> RefUnwindSafe for SectionBuilder<'a, Text>
where Text: RefUnwindSafe,

§

impl<'a, Text> Send for SectionBuilder<'a, Text>
where Text: Send,

§

impl<'a, Text> Sync for SectionBuilder<'a, Text>
where Text: Sync,

§

impl<'a, Text> Unpin for SectionBuilder<'a, Text>
where Text: Unpin,

§

impl<'a, Text> UnwindSafe for SectionBuilder<'a, Text>
where Text: 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,