Opt

Struct Opt 

Source
pub struct Opt<'a, T = AnyText, U = NoUrl> { /* private fields */ }
Expand description

§Option Object

slack api docs 🔗

An object that represents a single selectable item in a

Implementations§

Source§

impl<'a> Opt<'a>

Source

pub fn builder() -> OptBuilderInit<'a>

Build a new option composition object

§Examples
use slack_blocks::{blocks::{Actions, Block},
                   compose::Opt,
                   elems::{select::Static, BlockElement},
                   text};

struct City {
  name: String,
  short_code: String,
}

impl City {
  pub fn new(name: impl ToString, short_code: impl ToString) -> Self {
    Self { name: name.to_string(),
           short_code: short_code.to_string() }
  }
}

let cities = vec![City::new("Seattle", "SEA"),
                  City::new("Portland", "PDX"),
                  City::new("Phoenix", "PHX")];

let options =
  cities.iter().map(|City { name, short_code }| {
                 Opt::builder().text_plain(name).value(short_code).build()
               });

let select = Static::builder().placeholder("Choose your favorite city!")
                              .action_id("fave_city")
                              .options(options)
                              .build();

let block: Block = Actions::builder().element(select).build().into();
Source§

impl<'a, T, U> Opt<'a, T, U>

Source

pub fn validate(&self) -> Result<(), ValidationErrors>

Available on crate feature validation only.

Validate that this Option composition object agrees with Slack’s model requirements

§Errors
  • If text longer than 75 chars
  • If value longer than 75 chars
  • If url longer than 3000 chars
  • If description longer than 75 chars
§Example
use std::iter::repeat;

use slack_blocks::compose::Opt;

let long_string: String = repeat(' ').take(76).collect();

let opt = Opt::builder().text_plain("My Option")
                        .value(long_string)
                        .build();

assert_eq!(true, matches!(opt.validate(), Err(_)));

Trait Implementations§

Source§

impl<'a, Multi, Placeholder, ActionId> AppendOptOrOptGroup<'a, Multi, Placeholder, ActionId> for Opt<'a, Plain, NoUrl>

Available on crate feature blox only.
Source§

type Output = StaticBuilder<'a, Multi, Placeholder, ActionId, Set<(options, Opt<'a, Contents>)>>

The builder state after adding the opt / opt group
Source§

fn add_to( self, builder: StaticBuilder<'a, Multi, Placeholder, ActionId, RequiredMethodNotCalled<options>>, ) -> Self::Output

Add this opt / opt group to the builder
Source§

impl<'a, T: Clone, U: Clone> Clone for Opt<'a, T, U>

Source§

fn clone(&self) -> Opt<'a, T, U>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, T: Debug, U: Debug> Debug for Opt<'a, T, U>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de, 'a, T, U> Deserialize<'de> for Opt<'a, T, U>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a, T: Into<Text>, U> From<Opt<'a, T, U>> for Opt<'a, AnyText, U>

Source§

fn from(o: Opt<'a, T, U>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T, U> From<Opt<'a, T, U>> for OptOrOptGroup<'a, T, U>

Source§

fn from(src: Opt<'a, T, U>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Hash, U: Hash> Hash for Opt<'a, T, U>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, T: PartialEq, U: PartialEq> PartialEq for Opt<'a, T, U>

Source§

fn eq(&self, other: &Opt<'a, T, U>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T, U> Serialize for Opt<'a, T, U>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'a, T, U> Validate for Opt<'a, T, U>

Source§

impl<'a, T, U> StructuralPartialEq for Opt<'a, T, U>

Auto Trait Implementations§

§

impl<'a, T, U> Freeze for Opt<'a, T, U>

§

impl<'a, T, U> RefUnwindSafe for Opt<'a, T, U>

§

impl<'a, T, U> Send for Opt<'a, T, U>
where T: Send, U: Send,

§

impl<'a, T, U> Sync for Opt<'a, T, U>
where T: Sync, U: Sync,

§

impl<'a, T, U> Unpin for Opt<'a, T, U>
where T: Unpin, U: Unpin,

§

impl<'a, T, U> UnwindSafe for Opt<'a, T, U>
where 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,