pub struct Card { /* private fields */ }Expand description
Card block representation.
§Fields and Validations
For more details, see the official documentation.
| Field | Type | Required | Validation |
|---|---|---|---|
| block_id | String | No | Maximum 255 characters |
| hero_image | Image | No | N/A |
| icon | Image | No | N/A |
| title | TextContent | No | Maximum 150 characters |
| subtitle | TextContent | No | Maximum 150 characters |
| body | TextContent | No | Maximum 200 characters |
| actions | Vec<Button> | No | N/A |
§Validation Across Fields
- At least one of
hero_image,title,actions, orbodyis required.
§Example
use slack_messaging::{plain_text, mrkdwn};
use slack_messaging::blocks::Card;
use slack_messaging::blocks::elements::{Button, Image};
let card = Card::builder()
.icon(
Image::builder()
.image_url("https://picsum.photos/36/36")
.alt_text("Icon")
.build()?
)
.title(mrkdwn!("Lumon Industries")?)
.subtitle(mrkdwn!("Committed to work-life balance")?)
.hero_image(
Image::builder()
.image_url("https://picsum.photos/400/300")
.alt_text("Sample hero image")
.build()?
)
.body(mrkdwn!("Please enjoy each card equally.")?)
.action(
Button::builder()
.text(plain_text!("Action Button")?)
.action_id("button_action")
.build()?
)
.build()?;
let expected = serde_json::json!({
"type": "card",
"icon": {
"type": "image",
"image_url": "https://picsum.photos/36/36",
"alt_text": "Icon"
},
"title": {
"type": "mrkdwn",
"text": "Lumon Industries"
},
"subtitle": {
"type": "mrkdwn",
"text": "Committed to work-life balance"
},
"hero_image": {
"type": "image",
"image_url": "https://picsum.photos/400/300",
"alt_text": "Sample hero image"
},
"body": {
"type": "mrkdwn",
"text": "Please enjoy each card equally."
},
"actions": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Action Button"
},
"action_id": "button_action"
}
]
});
let json = serde_json::to_value(card).unwrap();
assert_eq!(json, expected);Implementations§
Source§impl Card
impl Card
Sourcepub fn builder() -> CardBuilder
pub fn builder() -> CardBuilder
constract CardBuilder object.
Trait Implementations§
impl StructuralPartialEq for Card
Auto Trait Implementations§
impl Freeze for Card
impl RefUnwindSafe for Card
impl Send for Card
impl Sync for Card
impl Unpin for Card
impl UnsafeUnpin for Card
impl UnwindSafe for Card
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more