Expand description
§slackblocks for Rust
A native Rust implementation of Slack Block Kit, using coordinated version 2.7.0 and shared specification 1.2.0.
Rust 2024; minimum supported Rust version (MSRV) 1.85. Values own their data,
builders consume themselves, getters borrow, and invalid input returns
ValidationError. The core depends only on Serde and serde_json.
All shared model types are implemented. Independent native examples and checked JSON ingress cover every shared valid fixture and invalid case. See the implementation plan for the train and acceptance evidence.
§Installation
Add the crate and serde_json to your application:
cargo add slackblocks@2.7.0
cargo add serde_jsonuse slackblocks::{ButtonElement, MessagePayload, SectionBlock};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let button = ButtonElement::builder().text("Open build").action_id("open_build").build()?;
let section = SectionBlock::builder().text("Build passed").accessory(button).build()?;
let message = MessagePayload::builder("C01234567")
.text("Build passed")
.block(section)
.build()?;
let edited = message.clone().into_builder().text("Build passed on main").build()?;
assert_eq!(message.text(), Some("Build passed"));
println!("{}", serde_json::to_string(&edited)?);
Ok(())
}§Native API conventions
- Builders consume themselves;
build()returnsResult<T, ValidationError>. Built values have private fields, own their data, and expose borrowed getters. - Clone a value before
into_builder()when both versions are needed. Plural collection setters replace; singular setters append. Iterators are accepted. - Concrete children convert into role enums with
From; unsupported roles fail at compile time. Vocabulary and role enums are#[non_exhaustive]. SelectOption,SelectOptionGroup, andConfirmationDialogueavoid ambiguous Rust names. No SDK class hierarchy is copied into the crate.- Strings coerce according to each text field. Use
PlainTextorMarkdownTextexplicitly when you need flags or a particular allowed text kind. - Fresh builders use documented model defaults. Checked parsing and editing
preserve omitted fields;
clear_*()removes optional defaults. Allowed false, zero and empty values remain present. Block IDs are omitted unless supplied. - Every modeled value supports Serde serialization and checked deserialization,
plus
TryFrom<serde_json::Value>for structuredValidationErroraccess. This is outbound Block Kit parsing, not an arbitrary Slack event decoder. - Extensions preserve unknown JSON but reject empty keys, modeled fields and
typecollisions.BuilderPayload::Rawis an explicit unvalidated preview input. JsonNumberpreservesi64/u64integers and finite floating-point values; unsupported precision and nonfinite inputs are rejected. The crate enables serde_json’sarbitrary_precisionfeature to check original JSON literals before narrowing them to the supported numeric range. A caller-supplied value already rounded before conversion cannot recover its original literal. Text lengths count Unicode code points.
§Helpers and transport
AccordionSection and Accordion compose collapsible containers. Paginator
uses one-based pages and .previous/.next action IDs; applications handle the
interaction and render the requested page. Both expand into ordinary Block
values, so the receiving message/view validates aggregate constraints.
Workflow::from_url accepts ordered input parameters and omits an empty parameter
list. AttachmentColor supports named constants and checked hexadecimal parsing.
block_kit_builder_url takes borrowed blocks/payloads and creates an encoded URL.
Serialize a MessagePayload, WebhookMessage or MessageResponse through Serde
and hand it to an application-owned HTTP client. ModalView and HomeTabView
belong inside the appropriate Slack request envelope. The crate makes no network
requests and imposes no async runtime. Check Slack’s JSON ok/error response as
well as HTTP status. Python’s deprecated legacy attachment Field is outside the
shared contract and is deliberately not reproduced.
Runnable Slack Morphism and reqwest examples show authenticated delivery, Slack errors, bounded rate-limit retries and timeouts. The sending guide displays their tested source. The separate application project and its lockfile are verified on Rust 1.85 and stable; HTTP and async dependencies stay outside the published crate. Tests use local mock servers and need no Slack credentials.
§Support and reference
MSRV is 1.85.0; raising it requires an explicit compatibility decision and release notes. CI tests minimum Rust and stable, plus stable on Linux, macOS and Windows. Serde/serde_json use compatible version requirements. Fresh consumers test the declared dependency lower bounds and serde_json feature unification independently of the development lockfile.
Rust support starts at coordinated 2.6.0; no earlier Rust API migration is needed.
Read the guides
and API reference,
or run cargo doc --manifest-path rust/Cargo.toml --no-deps --open for native
rustdoc and trait implementations.
§Development
Install stable Rust and Rust 1.85.0 with rustfmt and Clippy, plus Python 3.11+ for the development-only generator. The package itself does not need Python. Formatting is pinned to Rust 1.85.0; current stable owns Clippy and rustdoc checks.
export RUSTFMT="$(rustup which --toolchain 1.85.0 rustfmt)"
python3 rust/generator/generate.py
rust/bin/check
python3 rust/bin/check-package.py --toolchain 1.85.0 --all-consumers
python3 rust/bin/check-package.py --toolchain stableCI runs stable on Linux, macOS, and Windows and the minimum toolchain on Linux. Package checks extract the actual Cargo archive and compile fresh consumers against that extracted artifact, without access to the checkout’s Rust sources.
Quality checks include independent API and contract audits, property tests, and negative compile checks with a passing companion. CI enforces at least 90% line and 90% region coverage independently for the whole crate and handwritten code:
rustup component add llvm-tools-preview --toolchain stable
cargo +stable install cargo-llvm-cov --version 0.9.1 --locked
python3 rust/bin/check-coverage.pyOnly external code, test/example harnesses, and files containing no executable regions are excluded. Coverage is measured on stable Rust; it is not a branch coverage claim. The report also exercises consumer-enabled serde_json features.
For explicit response visibility, replacement and delete-only payloads, see the
response URL recipes.
WebhookMessage supports native delete_original; MessageResponse does not expose that field.
Structs§
- Accordion
- A nonempty ordered collection of collapsible sections.
- Accordion
Section - A validated, collapsible section of an
Accordion. - Accordion
Section Builder - Consuming builder for an accordion section.
- Actions
Block - A block that holds interactive elements such as buttons and menus.
- Actions
Block Builder - Consuming builder for
ActionsBlock. Validation runs inSelf::build. - Alert
Block - A severity-labelled alert, available in modals.
- Alert
Block Builder - Consuming builder for
AlertBlock. Validation runs inSelf::build. - Area
Chart - An area chart for a data visualization block.
- Area
Chart Builder - Consuming builder for
AreaChart. Validation runs inSelf::build. - Attachment
- A legacy message attachment containing blocks and an optional color bar.
- Attachment
Builder - Consuming builder for
Attachment. Validation runs inSelf::build. - Attachment
Color - A semantic or six-digit hexadecimal attachment color.
- Axis
Config - The categories and labels shared by bar, area, and line chart axes.
- Axis
Config Builder - Consuming builder for
AxisConfig. Validation runs inSelf::build. - BarChart
- A bar chart for a data visualization block.
- BarChart
Builder - Consuming builder for
BarChart. Validation runs inSelf::build. - Button
Element - An interactive button that sends a payload or opens a URL.
- Button
Element Builder - Consuming builder for
ButtonElement. Validation runs inSelf::build. - Card
Block - A compact card with an image, text, and up to three buttons.
- Card
Block Builder - Consuming builder for
CardBlock. Validation runs inSelf::build. - Carousel
Block - A horizontally scrolling set of cards, available in messages and App Home.
- Carousel
Block Builder - Consuming builder for
CarouselBlock. Validation runs inSelf::build. - Channel
Multi Select Element - A menu for selecting multiple public channels.
- Channel
Multi Select Element Builder - Consuming builder for
ChannelMultiSelectElement. Validation runs inSelf::build. - Channel
Select Element - A menu for selecting one public channel.
- Channel
Select Element Builder - Consuming builder for
ChannelSelectElement. Validation runs inSelf::build. - Chart
Segment - One labelled segment of a pie chart.
- Chart
Segment Builder - Consuming builder for
ChartSegment. Validation runs inSelf::build. - Checkboxes
Element - A group of checkboxes.
- Checkboxes
Element Builder - Consuming builder for
CheckboxesElement. Validation runs inSelf::build. - Column
Settings - Alignment and wrapping settings for one table column.
- Column
Settings Builder - Consuming builder for
ColumnSettings. Validation runs inSelf::build. - Confirmation
Dialogue - A dialog that asks users to confirm an action before it is sent.
- Confirmation
Dialogue Builder - Consuming builder for
ConfirmationDialogue. Validation runs inSelf::build. - Container
Block - A titled group of blocks that can optionally collapse.
- Container
Block Builder - Consuming builder for
ContainerBlock. Validation runs inSelf::build. - Context
Actions Block - A row of feedback or icon buttons, usually shown below AI-generated content.
- Context
Actions Block Builder - Consuming builder for
ContextActionsBlock. Validation runs inSelf::build. - Context
Block - A block of small, secondary images and text.
- Context
Block Builder - Consuming builder for
ContextBlock. Validation runs inSelf::build. - Conversation
Filter - Limits which conversations a conversation menu offers.
- Conversation
Filter Builder - Consuming builder for
ConversationFilter. Validation runs inSelf::build. - Conversation
Multi Select Element - A menu for selecting multiple conversations.
- Conversation
Multi Select Element Builder - Consuming builder for
ConversationMultiSelectElement. Validation runs inSelf::build. - Conversation
Select Element - A menu for selecting one conversation.
- Conversation
Select Element Builder - Consuming builder for
ConversationSelectElement. Validation runs inSelf::build. - Data
Point - One value of a chart series, keyed by axis category.
- Data
Point Builder - Consuming builder for
DataPoint. Validation runs inSelf::build. - Data
Series - A named series of chart data points.
- Data
Series Builder - Consuming builder for
DataSeries. Validation runs inSelf::build. - Data
Table Block - A sortable, paginated table of raw text, numbers, and rich text.
- Data
Table Block Builder - Consuming builder for
DataTableBlock. Validation runs inSelf::build. - Data
Visualization Block - A titled pie, bar, area, or line chart.
- Data
Visualization Block Builder - Consuming builder for
DataVisualizationBlock. Validation runs inSelf::build. - Date
Picker Element - A calendar date picker.
- Date
Picker Element Builder - Consuming builder for
DatePickerElement. Validation runs inSelf::build. - Date
Time Picker Element - A combined date and time picker.
- Date
Time Picker Element Builder - Consuming builder for
DateTimePickerElement. Validation runs inSelf::build. - Dispatch
Action Configuration - Chooses which interactions with an input send a block_actions payload.
- Dispatch
Action Configuration Builder - Consuming builder for
DispatchActionConfiguration. Validation runs inSelf::build. - Divider
Block - A horizontal rule that separates blocks.
- Divider
Block Builder - Consuming builder for
DividerBlock. Validation runs inSelf::build. - Email
Input Element - A single-line input that accepts an email address.
- Email
Input Element Builder - Consuming builder for
EmailInputElement. Validation runs inSelf::build. - External
Multi Select Element - A menu for selecting multiple options loaded from your app.
- External
Multi Select Element Builder - Consuming builder for
ExternalMultiSelectElement. Validation runs inSelf::build. - External
Select Element - A menu for selecting one option loaded from your app.
- External
Select Element Builder - Consuming builder for
ExternalSelectElement. Validation runs inSelf::build. - Feedback
Button - One button of a feedback buttons element.
- Feedback
Button Builder - Consuming builder for
FeedbackButton. Validation runs inSelf::build. - Feedback
Buttons Element - A pair of thumbs-up and thumbs-down feedback buttons.
- Feedback
Buttons Element Builder - Consuming builder for
FeedbackButtonsElement. Validation runs inSelf::build. - File
Block - A retrieved remote-file representation. Register and share files through the files.remote API; Slack does not accept directly posting file blocks.
- File
Block Builder - Consuming builder for
FileBlock. Validation runs inSelf::build. - File
Input Element - An input that lets users upload files.
- File
Input Element Builder - Consuming builder for
FileInputElement. Validation runs inSelf::build. - Header
Block - Large, bold plain text that introduces a group of blocks.
- Header
Block Builder - Consuming builder for
HeaderBlock. Validation runs inSelf::build. - Home
TabView - The payload for publishing an App Home tab with views.publish.
- Home
TabView Builder - Consuming builder for
HomeTabView. Validation runs inSelf::build. - Icon
Button Element - A button that shows an icon instead of text.
- Icon
Button Element Builder - Consuming builder for
IconButtonElement. Validation runs inSelf::build. - Image
Block - A standalone image with alternative text and an optional title.
- Image
Block Builder - Consuming builder for
ImageBlock. Validation runs inSelf::build. - Image
Element - An image displayed inside a section, context, or card.
- Image
Element Builder - Consuming builder for
ImageElement. Validation runs inSelf::build. - Input
Block - A labelled input that collects a value in a modal, App Home, or message.
- Input
Block Builder - Consuming builder for
InputBlock. Validation runs inSelf::build. - Input
Parameter - A named value passed to a workflow trigger.
- Input
Parameter Builder - Consuming builder for
InputParameter. Validation runs inSelf::build. - Json
Number - A JSON integer, unsigned integer, or finite floating-point number.
- Layout
Block - A visual grid of one to five rows on messages, modals, and App Home. Supply fallback content for older clients.
- Layout
Block Builder - Consuming builder for
LayoutBlock. Validation runs inSelf::build. - Layout
Item - One supported child block with a proportional width and optional direction-aware alignment.
- Layout
Item Builder - Consuming builder for
LayoutItem. Validation runs inSelf::build. - Layout
Row - One to three layout items in reading order. A row has no alignment or discriminator.
- Layout
RowBuilder - Consuming builder for
LayoutRow. Validation runs inSelf::build. - Line
Chart - A line chart for a data visualization block.
- Line
Chart Builder - Consuming builder for
LineChart. Validation runs inSelf::build. - Markdown
Block - Standard markdown rendered by Slack, intended for AI-generated content.
- Markdown
Block Builder - Consuming builder for
MarkdownBlock. Validation runs inSelf::build. - Markdown
Text - A mrkdwn text composition object.
- Markdown
Text Builder - Consuming builder for
MarkdownText. Validation runs inSelf::build. - Message
Payload - A complete payload for chat.postMessage and related Web API methods.
- Message
Payload Builder - Consuming builder for
MessagePayload. Validation runs inSelf::build. - Message
Response - A response body for slash commands and interaction response URLs.
- Message
Response Builder - Consuming builder for
MessageResponse. Validation runs inSelf::build. - Modal
View - The view payload for views.open, views.push, and views.update.
- Modal
View Builder - Consuming builder for
ModalView. Validation runs inSelf::build. - Number
Input Element - An input that accepts whole or decimal numbers.
- Number
Input Element Builder - Consuming builder for
NumberInputElement. Validation runs inSelf::build. - Overflow
Element - A compact menu of up to five options.
- Overflow
Element Builder - Consuming builder for
OverflowElement. Validation runs inSelf::build. - Paginator
- A validated page of blocks and its navigation controls.
- Paginator
Builder - Consuming configuration for a
Paginator. - PieChart
- A pie chart for a data visualization block.
- PieChart
Builder - Consuming builder for
PieChart. Validation runs inSelf::build. - Plain
Text - A plain-text composition object.
- Plain
Text Builder - Consuming builder for
PlainText. Validation runs inSelf::build. - Plain
Text Input - A plain-text builder argument: either an owned string or validated plain text.
- Plain
Text Input Element - A single-line or multi-line free-text input.
- Plain
Text Input Element Builder - Consuming builder for
PlainTextInputElement. Validation runs inSelf::build. - Plan
Block - A titled sequence of task cards.
- Plan
Block Builder - Consuming builder for
PlanBlock. Validation runs inSelf::build. - Radio
Buttons Element - A group of radio buttons.
- Radio
Buttons Element Builder - Consuming builder for
RadioButtonsElement. Validation runs inSelf::build. - RawNumber
- A numeric table or data table cell with display text.
- RawNumber
Builder - Consuming builder for
RawNumber. Validation runs inSelf::build. - RawText
- An unformatted table cell.
- RawText
Builder - Consuming builder for
RawText. Validation runs inSelf::build. - Rich
Text Block - Formatted text built from sections, lists, preformatted blocks, and quotes.
- Rich
Text Block Builder - Consuming builder for
RichTextBlock. Validation runs inSelf::build. - Rich
Text Channel - A channel mention inside rich text.
- Rich
Text Channel Builder - Consuming builder for
RichTextChannel. Validation runs inSelf::build. - Rich
Text Code Block - A preformatted code block inside rich text.
- Rich
Text Code Block Builder - Consuming builder for
RichTextCodeBlock. Validation runs inSelf::build. - Rich
Text Emoji - An emoji inside rich text.
- Rich
Text Emoji Builder - Consuming builder for
RichTextEmoji. Validation runs inSelf::build. - Rich
Text Input Element - An input that accepts formatted rich text.
- Rich
Text Input Element Builder - Consuming builder for
RichTextInputElement. Validation runs inSelf::build. - Rich
Text Link - A hyperlink inside rich text.
- Rich
Text Link Builder - Consuming builder for
RichTextLink. Validation runs inSelf::build. - Rich
Text List - A bulleted or numbered list inside rich text.
- Rich
Text List Builder - Consuming builder for
RichTextList. Validation runs inSelf::build. - Rich
Text Quote - A quotation inside rich text.
- Rich
Text Quote Builder - Consuming builder for
RichTextQuote. Validation runs inSelf::build. - Rich
Text Section - A paragraph of inline rich text elements.
- Rich
Text Section Builder - Consuming builder for
RichTextSection. Validation runs inSelf::build. - Rich
Text Style - Optional rich-text style flags. Each receiving element validates its allowed subset.
- Rich
Text Text - A run of optionally styled text inside rich text.
- Rich
Text Text Builder - Consuming builder for
RichTextText. Validation runs inSelf::build. - Rich
Text User - A user mention inside rich text.
- Rich
Text User Builder - Consuming builder for
RichTextUser. Validation runs inSelf::build. - Rich
Text User Group - A user group mention inside rich text.
- Rich
Text User Group Builder - Consuming builder for
RichTextUserGroup. Validation runs inSelf::build. - Section
Block - Text, a grid of fields, or both, with an optional accessory element.
- Section
Block Builder - Consuming builder for
SectionBlock. Validation runs inSelf::build. - Select
Option - A selectable option for menus, checkboxes, radio buttons, and overflow menus.
- Select
Option Builder - Consuming builder for
SelectOption. Validation runs inSelf::build. - Select
Option Group - A labelled group of options in a static select menu.
- Select
Option Group Builder - Consuming builder for
SelectOptionGroup. Validation runs inSelf::build. - Slack
File - A reference to an image file hosted in Slack.
- Slack
File Builder - Consuming builder for
SlackFile. Validation runs inSelf::build. - Slack
Icon - A Slack-provided icon, referenced by name.
- Slack
Icon Builder - Consuming builder for
SlackIcon. Validation runs inSelf::build. - Static
Multi Select Element - A menu for selecting multiple options defined in the payload.
- Static
Multi Select Element Builder - Consuming builder for
StaticMultiSelectElement. Validation runs inSelf::build. - Static
Select Element - A menu for selecting one option defined in the payload.
- Static
Select Element Builder - Consuming builder for
StaticSelectElement. Validation runs inSelf::build. - Table
Block - A simple table of raw text, numeric and rich text cells. Cell text is limited to 10,000 Unicode code points per table and across tables in a message.
- Table
Block Builder - Consuming builder for
TableBlock. Validation runs inSelf::build. - Task
Card Block - One task with its status, details, output, and sources.
- Task
Card Block Builder - Consuming builder for
TaskCardBlock. Validation runs inSelf::build. - Text
Input - A text builder argument. Strings use the receiving field’s documented text kind.
There is deliberately no global string-to-
Textconversion. - Time
Picker Element - A time-of-day picker.
- Time
Picker Element Builder - Consuming builder for
TimePickerElement. Validation runs inSelf::build. - Trigger
- A link trigger that starts a workflow.
- Trigger
Builder - Consuming builder for
Trigger. Validation runs inSelf::build. - UrlInput
Element - A single-line input that accepts a URL.
- UrlInput
Element Builder - Consuming builder for
UrlInputElement. Validation runs inSelf::build. - UrlSource
- A linked source cited by a task card.
- UrlSource
Builder - Consuming builder for
UrlSource. Validation runs inSelf::build. - User
Multi Select Element - A menu for selecting multiple workspace users.
- User
Multi Select Element Builder - Consuming builder for
UserMultiSelectElement. Validation runs inSelf::build. - User
Select Element - A menu for selecting one workspace user.
- User
Select Element Builder - Consuming builder for
UserSelectElement. Validation runs inSelf::build. - Validation
Error - A checked-construction or parsing error, with a full Slack wire-field path.
- Video
Block - An embedded video player.
- Video
Block Builder - Consuming builder for
VideoBlock. Validation runs inSelf::build. - Webhook
Message - A payload for incoming webhooks.
- Webhook
Message Builder - Consuming builder for
WebhookMessage. Validation runs inSelf::build. - Workflow
- The workflow started by a workflow button.
- Workflow
Builder - Consuming builder for
Workflow. Validation runs inSelf::build. - Workflow
Button Element - A button that starts a workflow through a link trigger.
- Workflow
Button Element Builder - Consuming builder for
WorkflowButtonElement. Validation runs inSelf::build.
Enums§
- Alert
Level - Severity levels supported by alert blocks.
- Block
- A validated Slack layout block accepted directly by a JSON transport.
- Builder
Payload - Borrowed input shapes for a Block Kit Builder preview URL.
- Button
Style - Visual emphasis for buttons and confirmation dialogs.
- Chart
- A chart that can be displayed by a data visualization block.
- Column
Align - Horizontal alignment for table columns.
- Container
Width - Widths supported by Slack container blocks.
- Context
Actions Element - A value that can appear in a context actions block: feedback buttons or an icon button.
- Context
Element - A value that can appear in a context block: an image element or a text object.
- Data
Table Cell - A value that can appear as a data table cell: raw text, a raw number, or a rich text block.
- Element
- A validated interactive, visual, or input element nested inside a Slack block.
- Error
Category - The shared validation category; message wording is not a compatibility promise.
- Icon
Button Icon - Icons supported by icon buttons.
- Input
Element - An element that can be placed in an input block.
- Layout
Alignment - Direction-aware alignment within a layout item. Omit for fill behavior.
- Layout
Child - A block that can occupy a layout item; it must also be valid on the enclosing surface.
- Layout
Fallback - A stable block that older clients render in place of a layout.
- Layout
Grid Lines - Layout borders: none, outer border with horizontal row dividers, or outer border only.
- Layout
Width - Relative layout item weights: narrow is 1, standard is 2, and wide is 3.
- Response
Type - Visibility of a slash-command or interaction response.
- Rich
Text Block Element - A top-level element of a rich text block: a section, list, preformatted block, or quote.
- Rich
Text List Style - Marker styles for rich text lists.
- Rich
Text Section Element - An inline rich text element: text, a link, an emoji, or a channel, user, or user group mention.
- Table
Cell - A value that can appear as a table block cell: raw text, a raw number, or a rich text block.
- Task
Status - States supported by task card blocks.
- Text
- A Slack text composition object: plain text or mrkdwn.
Constants§
- SPEC_
VERSION - Version of the shared Slack Block Kit contract.
- VERSION
- The Cargo package version; independent of the shared specification version.
Functions§
- block_
kit_ builder_ url - Creates a Slack Block Kit Builder URL without performing any network requests. Optional team IDs are encoded as a single path segment. JSON is encoded as UTF-8.