pub struct OptGroup<T = Text<Plain>>where
T: TextExt,{ /* private fields */ }Expand description
Option group object representation.
This is a generic struct that can represent an option group object with different text object types.
§Type Parameters
T: The type of text object used for thetextfield of theOptobjects in theoptionsfield. Defaults toText<Plain>. Must implement theTextExttrait.
§Fields and Validations
For more details, see the official documentation.
| Field | Type | Required | Validation |
|---|---|---|---|
| label | Text<Plain> | Yes | Max length 75 characters |
| options | Vec<Opt<T>> | Yes | Must contain at most 100 items |
§Example
use slack_messaging::plain_text;
use slack_messaging::composition_objects::{OptGroup, Opt, Plain, Text};
let options: OptGroup = OptGroup::builder()
.label(plain_text!("Group One")?)
.option(
Opt::builder()
.text(plain_text!("option-0")?)
.value("value-0")
.build()?
)
.option(
Opt::builder()
.text(plain_text!("option-1")?)
.value("value-1")
.build()?
)
.build()?;
let expected = serde_json::json!({
"label": {
"type": "plain_text",
"text": "Group One"
},
"options": [
{
"text": {
"type": "plain_text",
"text": "option-0",
},
"value": "value-0"
},
{
"text": {
"type": "plain_text",
"text": "option-1"
},
"value": "value-1"
},
]
});
let json = serde_json::to_value(options).unwrap();
assert_eq!(json, expected);
// If your object has any validation errors, the build method returns Result::Err
let options = OptGroup::<Text<Plain>>::builder()
.label(plain_text!("Group One")?)
.build();
assert!(options.is_err());Implementations§
Source§impl<T> OptGroup<T>where
T: TextExt,
impl<T> OptGroup<T>where
T: TextExt,
Sourcepub fn builder() -> OptGroupBuilder<T>
pub fn builder() -> OptGroupBuilder<T>
constract OptGroupBuilder object.
Trait Implementations§
impl<T> StructuralPartialEq for OptGroup<T>where
T: TextExt,
Auto Trait Implementations§
impl<T> Freeze for OptGroup<T>
impl<T> RefUnwindSafe for OptGroup<T>where
T: RefUnwindSafe,
impl<T> Send for OptGroup<T>where
T: Send,
impl<T> Sync for OptGroup<T>where
T: Sync,
impl<T> Unpin for OptGroup<T>where
T: Unpin,
impl<T> UnwindSafe for OptGroup<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)