[−][src]Struct slack_blocks::blocks::input::Contents
Input Block
A block that collects information from users -
Read slack's guide to using modals 🔗 to learn how input blocks pass information to your app.
Implementations
impl Contents[src]
pub fn from_label_and_element<Label: Into<Text>, El: Into<InputElement>>(
label: Label,
element: El
) -> Self[src]
label: Label,
element: El
) -> Self
Create an Input Block from a text Label and interactive element.
Arguments
-
label- A label that appears above an input element in the form of a text object 🔗 that must have type ofplain_text. Maximum length for the text in this field is 2000 characters. -
element- An interactiveblock_elementthat will be used to gather the input for this block. For the kinds of Elements supported by Input blocks, see theInputElementenum. For info about Block Elements in general, see theblock_elementsmodule.
Example
use slack_blocks::block_elements::select; use slack_blocks::blocks; use slack_blocks::compose; let label = compose::Text::plain("On a scale from 1 - 5, how angsty are you?"); let input = select::Static {}; let block = blocks::input::Contents::from_label_and_element(label, input); // < send to slack API >
pub fn with_block_id<StrIsh: AsRef<str>>(self, block_id: StrIsh) -> Self[src]
Set a unique block_id to identify this instance of an Input Block.
Arguments
block_id- A string acting as a unique identifier for a block. You can use thisblock_idwhen you receive an interaction payload to identify the source of the action 🔗. If not specified, one will be generated. Maximum length for this field is 255 characters.block_idshould be unique for each message and each iteration of a message. If a message is updated, use a newblock_id.
Example
use slack_blocks::block_elements::select; use slack_blocks::blocks; use slack_blocks::compose; let label = compose::Text::plain("On a scale from 1 - 5, how angsty are you?"); let input = select::Static {}; let block = blocks::input ::Contents ::from_label_and_element(label, input) .with_block_id("angst_rating_12345"); // < send to slack API >
pub fn with_hint<IntoText: Into<Text>>(self, hint: IntoText) -> Self[src]
Set the hint on this Input Block that appears below
an input element in a lighter grey.
Arguments
hint- An optional hint that appears below an input element in a lighter grey. It must be a a text object 🔗 with atypeofplain_text. Maximum length for thetextin this field is 2000 characters.
Example
use slack_blocks::block_elements::select; use slack_blocks::blocks; use slack_blocks::compose; let label = compose::Text::plain("On a scale from 1 - 5, how angsty are you?"); let input = select::Static {}; let block = blocks::input ::Contents ::from_label_and_element(label, input) .with_hint(compose::Text::plain("PSST hey! Don't let them know how angsty you are!")); // < send to slack API >
pub fn with_optional(self, optionality: bool) -> Self[src]
Set whether or not this input is Optional.
Arguments
optionality- A boolean that indicates whether the input element may be empty when a user submits the modal. Defaults to false.
Example
use slack_blocks::block_elements::select; use slack_blocks::blocks; use slack_blocks::compose; let label = compose::Text::plain("On a scale from 1 - 5, how angsty are you?"); let input = select::Static {}; let block = blocks::input ::Contents ::from_label_and_element(label, input) .with_hint(compose::Text::plain("PSST hey! Don't even answer that!")) .with_optional(true); // < send to slack API >
pub fn validate(&self) -> Result<(), ValidationErrors>[src]
Validate that this Input block agrees with Slack's model requirements
Errors
- If
from_label_and_elementwas passed a Text object longer than 2000 chars - If
with_hintwas called with a block id longer than 2000 chars - If
with_block_idwas called with a block id longer than 256 chars
Example
use slack_blocks::block_elements::select; use slack_blocks::blocks; use slack_blocks::compose; let label = compose::Text::plain("On a scale from 1 - 5, how angsty are you?"); let input = select::Static {}; let long_string = std::iter::repeat(' ').take(2001).collect::<String>(); let block = blocks::input ::Contents ::from_label_and_element(label, input) .with_block_id(long_string); assert_eq!(true, matches!(block.validate(), Err(_))); // < send to slack API >
Trait Implementations
impl Clone for Contents[src]
impl Debug for Contents[src]
impl<'de> Deserialize<'de> for Contents[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>, [src]
__D: Deserializer<'de>,
impl From<Contents> for Block[src]
impl Hash for Contents[src]
fn hash<__H: Hasher>(&self, state: &mut __H)[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
impl PartialEq<Contents> for Contents[src]
impl Serialize for Contents[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer, [src]
__S: Serializer,
impl StructuralPartialEq for Contents[src]
impl Validate for Contents[src]
fn validate(&self) -> Result<(), ValidationErrors>[src]
Auto Trait Implementations
impl RefUnwindSafe for Contents
impl Send for Contents
impl Sync for Contents
impl Unpin for Contents
impl UnwindSafe for Contents
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>, [src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,