use crate::wire::{self, FromWire};
use crate::{ErrorCategory, JsonNumber, PlainTextInput, RichTextStyle, TextInput, ValidationError};
use serde::ser::SerializeMap;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json::{Map, Value};
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum AlertLevel {
Default,
Info,
Warning,
Error,
Success,
}
impl AlertLevel {
pub const fn as_str(self) -> &'static str {
match self {
Self::Default => "default",
Self::Info => "info",
Self::Warning => "warning",
Self::Error => "error",
Self::Success => "success",
}
}
}
impl FromWire for AlertLevel {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.as_str() {
Some("default") => Ok(Self::Default),
Some("info") => Ok(Self::Info),
Some("warning") => Ok(Self::Warning),
Some("error") => Ok(Self::Error),
Some("success") => Ok(Self::Success),
_ => Err(wire::mismatch(path, "AlertLevel")),
}
}
}
impl Serialize for AlertLevel {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(self.as_str())
}
}
impl TryFrom<Value> for AlertLevel {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "AlertLevel")
}
}
impl<'de> Deserialize<'de> for AlertLevel {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl std::fmt::Display for AlertLevel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl std::str::FromStr for AlertLevel {
type Err = ValidationError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::try_from(Value::String(s.into()))
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum ContainerWidth {
Narrow,
Standard,
Wide,
Full,
}
impl ContainerWidth {
pub const fn as_str(self) -> &'static str {
match self {
Self::Narrow => "narrow",
Self::Standard => "standard",
Self::Wide => "wide",
Self::Full => "full",
}
}
}
impl FromWire for ContainerWidth {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.as_str() {
Some("narrow") => Ok(Self::Narrow),
Some("standard") => Ok(Self::Standard),
Some("wide") => Ok(Self::Wide),
Some("full") => Ok(Self::Full),
_ => Err(wire::mismatch(path, "ContainerWidth")),
}
}
}
impl Serialize for ContainerWidth {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(self.as_str())
}
}
impl TryFrom<Value> for ContainerWidth {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ContainerWidth")
}
}
impl<'de> Deserialize<'de> for ContainerWidth {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl std::fmt::Display for ContainerWidth {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl std::str::FromStr for ContainerWidth {
type Err = ValidationError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::try_from(Value::String(s.into()))
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum TaskStatus {
Pending,
InProgress,
Complete,
Error,
}
impl TaskStatus {
pub const fn as_str(self) -> &'static str {
match self {
Self::Pending => "pending",
Self::InProgress => "in_progress",
Self::Complete => "complete",
Self::Error => "error",
}
}
}
impl FromWire for TaskStatus {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.as_str() {
Some("pending") => Ok(Self::Pending),
Some("in_progress") => Ok(Self::InProgress),
Some("complete") => Ok(Self::Complete),
Some("error") => Ok(Self::Error),
_ => Err(wire::mismatch(path, "TaskStatus")),
}
}
}
impl Serialize for TaskStatus {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(self.as_str())
}
}
impl TryFrom<Value> for TaskStatus {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "TaskStatus")
}
}
impl<'de> Deserialize<'de> for TaskStatus {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl std::fmt::Display for TaskStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl std::str::FromStr for TaskStatus {
type Err = ValidationError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::try_from(Value::String(s.into()))
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum ButtonStyle {
Primary,
Danger,
}
impl ButtonStyle {
pub const fn as_str(self) -> &'static str {
match self {
Self::Primary => "primary",
Self::Danger => "danger",
}
}
}
impl FromWire for ButtonStyle {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.as_str() {
Some("primary") => Ok(Self::Primary),
Some("danger") => Ok(Self::Danger),
_ => Err(wire::mismatch(path, "ButtonStyle")),
}
}
}
impl Serialize for ButtonStyle {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(self.as_str())
}
}
impl TryFrom<Value> for ButtonStyle {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ButtonStyle")
}
}
impl<'de> Deserialize<'de> for ButtonStyle {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl std::fmt::Display for ButtonStyle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl std::str::FromStr for ButtonStyle {
type Err = ValidationError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::try_from(Value::String(s.into()))
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum IconButtonIcon {
Trash,
}
impl IconButtonIcon {
pub const fn as_str(self) -> &'static str {
match self {
Self::Trash => "trash",
}
}
}
impl FromWire for IconButtonIcon {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.as_str() {
Some("trash") => Ok(Self::Trash),
_ => Err(wire::mismatch(path, "IconButtonIcon")),
}
}
}
impl Serialize for IconButtonIcon {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(self.as_str())
}
}
impl TryFrom<Value> for IconButtonIcon {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "IconButtonIcon")
}
}
impl<'de> Deserialize<'de> for IconButtonIcon {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl std::fmt::Display for IconButtonIcon {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl std::str::FromStr for IconButtonIcon {
type Err = ValidationError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::try_from(Value::String(s.into()))
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum ColumnAlign {
Left,
Center,
Right,
}
impl ColumnAlign {
pub const fn as_str(self) -> &'static str {
match self {
Self::Left => "left",
Self::Center => "center",
Self::Right => "right",
}
}
}
impl FromWire for ColumnAlign {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.as_str() {
Some("left") => Ok(Self::Left),
Some("center") => Ok(Self::Center),
Some("right") => Ok(Self::Right),
_ => Err(wire::mismatch(path, "ColumnAlign")),
}
}
}
impl Serialize for ColumnAlign {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(self.as_str())
}
}
impl TryFrom<Value> for ColumnAlign {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ColumnAlign")
}
}
impl<'de> Deserialize<'de> for ColumnAlign {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl std::fmt::Display for ColumnAlign {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl std::str::FromStr for ColumnAlign {
type Err = ValidationError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::try_from(Value::String(s.into()))
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum RichTextListStyle {
Bullet,
Ordered,
}
impl RichTextListStyle {
pub const fn as_str(self) -> &'static str {
match self {
Self::Bullet => "bullet",
Self::Ordered => "ordered",
}
}
}
impl FromWire for RichTextListStyle {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.as_str() {
Some("bullet") => Ok(Self::Bullet),
Some("ordered") => Ok(Self::Ordered),
_ => Err(wire::mismatch(path, "RichTextListStyle")),
}
}
}
impl Serialize for RichTextListStyle {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(self.as_str())
}
}
impl TryFrom<Value> for RichTextListStyle {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextListStyle")
}
}
impl<'de> Deserialize<'de> for RichTextListStyle {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl std::fmt::Display for RichTextListStyle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl std::str::FromStr for RichTextListStyle {
type Err = ValidationError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::try_from(Value::String(s.into()))
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum ResponseType {
InChannel,
Ephemeral,
}
impl ResponseType {
pub const fn as_str(self) -> &'static str {
match self {
Self::InChannel => "in_channel",
Self::Ephemeral => "ephemeral",
}
}
}
impl FromWire for ResponseType {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.as_str() {
Some("in_channel") => Ok(Self::InChannel),
Some("ephemeral") => Ok(Self::Ephemeral),
_ => Err(wire::mismatch(path, "ResponseType")),
}
}
}
impl Serialize for ResponseType {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(self.as_str())
}
}
impl TryFrom<Value> for ResponseType {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ResponseType")
}
}
impl<'de> Deserialize<'de> for ResponseType {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl std::fmt::Display for ResponseType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl std::str::FromStr for ResponseType {
type Err = ValidationError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::try_from(Value::String(s.into()))
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Block {
Actions(Box<ActionsBlock>),
Alert(Box<AlertBlock>),
Card(Box<CardBlock>),
Carousel(Box<CarouselBlock>),
Container(Box<ContainerBlock>),
ContextActions(Box<ContextActionsBlock>),
Context(Box<ContextBlock>),
DataTable(Box<DataTableBlock>),
DataVisualization(Box<DataVisualizationBlock>),
Divider(Box<DividerBlock>),
File(Box<FileBlock>),
Header(Box<HeaderBlock>),
Image(Box<ImageBlock>),
Input(Box<InputBlock>),
Markdown(Box<MarkdownBlock>),
Plan(Box<PlanBlock>),
RichText(Box<RichTextBlock>),
Section(Box<SectionBlock>),
Table(Box<TableBlock>),
TaskCard(Box<TaskCardBlock>),
Video(Box<VideoBlock>),
}
impl Serialize for Block {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
match self {
Self::Actions(v) => v.serialize(s),
Self::Alert(v) => v.serialize(s),
Self::Card(v) => v.serialize(s),
Self::Carousel(v) => v.serialize(s),
Self::Container(v) => v.serialize(s),
Self::ContextActions(v) => v.serialize(s),
Self::Context(v) => v.serialize(s),
Self::DataTable(v) => v.serialize(s),
Self::DataVisualization(v) => v.serialize(s),
Self::Divider(v) => v.serialize(s),
Self::File(v) => v.serialize(s),
Self::Header(v) => v.serialize(s),
Self::Image(v) => v.serialize(s),
Self::Input(v) => v.serialize(s),
Self::Markdown(v) => v.serialize(s),
Self::Plan(v) => v.serialize(s),
Self::RichText(v) => v.serialize(s),
Self::Section(v) => v.serialize(s),
Self::Table(v) => v.serialize(s),
Self::TaskCard(v) => v.serialize(s),
Self::Video(v) => v.serialize(s),
}
}
}
impl FromWire for Block {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.get("type").and_then(Value::as_str) {
Some("actions") => ActionsBlock::from_wire(value, path).map(Into::into),
Some("alert") => AlertBlock::from_wire(value, path).map(Into::into),
Some("card") => CardBlock::from_wire(value, path).map(Into::into),
Some("carousel") => CarouselBlock::from_wire(value, path).map(Into::into),
Some("container") => ContainerBlock::from_wire(value, path).map(Into::into),
Some("context_actions") => ContextActionsBlock::from_wire(value, path).map(Into::into),
Some("context") => ContextBlock::from_wire(value, path).map(Into::into),
Some("data_table") => DataTableBlock::from_wire(value, path).map(Into::into),
Some("data_visualization") => {
DataVisualizationBlock::from_wire(value, path).map(Into::into)
}
Some("divider") => DividerBlock::from_wire(value, path).map(Into::into),
Some("file") => FileBlock::from_wire(value, path).map(Into::into),
Some("header") => HeaderBlock::from_wire(value, path).map(Into::into),
Some("image") => ImageBlock::from_wire(value, path).map(Into::into),
Some("input") => InputBlock::from_wire(value, path).map(Into::into),
Some("markdown") => MarkdownBlock::from_wire(value, path).map(Into::into),
Some("plan") => PlanBlock::from_wire(value, path).map(Into::into),
Some("rich_text") => RichTextBlock::from_wire(value, path).map(Into::into),
Some("section") => SectionBlock::from_wire(value, path).map(Into::into),
Some("table") => TableBlock::from_wire(value, path).map(Into::into),
Some("task_card") => TaskCardBlock::from_wire(value, path).map(Into::into),
Some("video") => VideoBlock::from_wire(value, path).map(Into::into),
_ => Err(wire::mismatch(
&format!("{path}.type"),
"a Block discriminator",
)),
}
}
}
impl TryFrom<Value> for Block {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "Block")
}
}
impl<'de> Deserialize<'de> for Block {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl Block {
pub(crate) fn wire_type(&self) -> &'static str {
match self {
Self::Actions(_) => "actions",
Self::Alert(_) => "alert",
Self::Card(_) => "card",
Self::Carousel(_) => "carousel",
Self::Container(_) => "container",
Self::ContextActions(_) => "context_actions",
Self::Context(_) => "context",
Self::DataTable(_) => "data_table",
Self::DataVisualization(_) => "data_visualization",
Self::Divider(_) => "divider",
Self::File(_) => "file",
Self::Header(_) => "header",
Self::Image(_) => "image",
Self::Input(_) => "input",
Self::Markdown(_) => "markdown",
Self::Plan(_) => "plan",
Self::RichText(_) => "rich_text",
Self::Section(_) => "section",
Self::Table(_) => "table",
Self::TaskCard(_) => "task_card",
Self::Video(_) => "video",
}
}
}
impl From<ActionsBlock> for Block {
fn from(value: ActionsBlock) -> Self {
Self::Actions(Box::new(value))
}
}
impl From<AlertBlock> for Block {
fn from(value: AlertBlock) -> Self {
Self::Alert(Box::new(value))
}
}
impl From<CardBlock> for Block {
fn from(value: CardBlock) -> Self {
Self::Card(Box::new(value))
}
}
impl From<CarouselBlock> for Block {
fn from(value: CarouselBlock) -> Self {
Self::Carousel(Box::new(value))
}
}
impl From<ContainerBlock> for Block {
fn from(value: ContainerBlock) -> Self {
Self::Container(Box::new(value))
}
}
impl From<ContextActionsBlock> for Block {
fn from(value: ContextActionsBlock) -> Self {
Self::ContextActions(Box::new(value))
}
}
impl From<ContextBlock> for Block {
fn from(value: ContextBlock) -> Self {
Self::Context(Box::new(value))
}
}
impl From<DataTableBlock> for Block {
fn from(value: DataTableBlock) -> Self {
Self::DataTable(Box::new(value))
}
}
impl From<DataVisualizationBlock> for Block {
fn from(value: DataVisualizationBlock) -> Self {
Self::DataVisualization(Box::new(value))
}
}
impl From<DividerBlock> for Block {
fn from(value: DividerBlock) -> Self {
Self::Divider(Box::new(value))
}
}
impl From<FileBlock> for Block {
fn from(value: FileBlock) -> Self {
Self::File(Box::new(value))
}
}
impl From<HeaderBlock> for Block {
fn from(value: HeaderBlock) -> Self {
Self::Header(Box::new(value))
}
}
impl From<ImageBlock> for Block {
fn from(value: ImageBlock) -> Self {
Self::Image(Box::new(value))
}
}
impl From<InputBlock> for Block {
fn from(value: InputBlock) -> Self {
Self::Input(Box::new(value))
}
}
impl From<MarkdownBlock> for Block {
fn from(value: MarkdownBlock) -> Self {
Self::Markdown(Box::new(value))
}
}
impl From<PlanBlock> for Block {
fn from(value: PlanBlock) -> Self {
Self::Plan(Box::new(value))
}
}
impl From<RichTextBlock> for Block {
fn from(value: RichTextBlock) -> Self {
Self::RichText(Box::new(value))
}
}
impl From<SectionBlock> for Block {
fn from(value: SectionBlock) -> Self {
Self::Section(Box::new(value))
}
}
impl From<TableBlock> for Block {
fn from(value: TableBlock) -> Self {
Self::Table(Box::new(value))
}
}
impl From<TaskCardBlock> for Block {
fn from(value: TaskCardBlock) -> Self {
Self::TaskCard(Box::new(value))
}
}
impl From<VideoBlock> for Block {
fn from(value: VideoBlock) -> Self {
Self::Video(Box::new(value))
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum ContextElement {
ImageElement(ImageElement),
MarkdownText(MarkdownText),
PlainText(PlainText),
}
impl Serialize for ContextElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
match self {
Self::ImageElement(v) => v.serialize(s),
Self::MarkdownText(v) => v.serialize(s),
Self::PlainText(v) => v.serialize(s),
}
}
}
impl FromWire for ContextElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.get("type").and_then(Value::as_str) {
Some("image") => ImageElement::from_wire(value, path).map(Into::into),
Some("mrkdwn") => MarkdownText::from_wire(value, path).map(Into::into),
Some("plain_text") => PlainText::from_wire(value, path).map(Into::into),
_ => Err(wire::mismatch(
&format!("{path}.type"),
"a ContextElement discriminator",
)),
}
}
}
impl TryFrom<Value> for ContextElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ContextElement")
}
}
impl<'de> Deserialize<'de> for ContextElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl From<ImageElement> for ContextElement {
fn from(value: ImageElement) -> Self {
Self::ImageElement(value)
}
}
impl From<MarkdownText> for ContextElement {
fn from(value: MarkdownText) -> Self {
Self::MarkdownText(value)
}
}
impl From<PlainText> for ContextElement {
fn from(value: PlainText) -> Self {
Self::PlainText(value)
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum ContextActionsElement {
FeedbackButtons(Box<FeedbackButtonsElement>),
IconButton(Box<IconButtonElement>),
}
impl Serialize for ContextActionsElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
match self {
Self::FeedbackButtons(v) => v.serialize(s),
Self::IconButton(v) => v.serialize(s),
}
}
}
impl FromWire for ContextActionsElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.get("type").and_then(Value::as_str) {
Some("feedback_buttons") => {
FeedbackButtonsElement::from_wire(value, path).map(Into::into)
}
Some("icon_button") => IconButtonElement::from_wire(value, path).map(Into::into),
_ => Err(wire::mismatch(
&format!("{path}.type"),
"a ContextActionsElement discriminator",
)),
}
}
}
impl TryFrom<Value> for ContextActionsElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ContextActionsElement")
}
}
impl<'de> Deserialize<'de> for ContextActionsElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl From<FeedbackButtonsElement> for ContextActionsElement {
fn from(value: FeedbackButtonsElement) -> Self {
Self::FeedbackButtons(Box::new(value))
}
}
impl From<IconButtonElement> for ContextActionsElement {
fn from(value: IconButtonElement) -> Self {
Self::IconButton(Box::new(value))
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum TableCell {
RichText(RichTextBlock),
RawText(RawText),
}
impl Serialize for TableCell {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
match self {
Self::RichText(v) => v.serialize(s),
Self::RawText(v) => v.serialize(s),
}
}
}
impl FromWire for TableCell {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.get("type").and_then(Value::as_str) {
Some("rich_text") => RichTextBlock::from_wire(value, path).map(Into::into),
Some("raw_text") => RawText::from_wire(value, path).map(Into::into),
_ => Err(wire::mismatch(
&format!("{path}.type"),
"a TableCell discriminator",
)),
}
}
}
impl TryFrom<Value> for TableCell {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "TableCell")
}
}
impl<'de> Deserialize<'de> for TableCell {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl From<RichTextBlock> for TableCell {
fn from(value: RichTextBlock) -> Self {
Self::RichText(value)
}
}
impl From<RawText> for TableCell {
fn from(value: RawText) -> Self {
Self::RawText(value)
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum DataTableCell {
RichText(RichTextBlock),
RawNumber(RawNumber),
RawText(RawText),
}
impl Serialize for DataTableCell {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
match self {
Self::RichText(v) => v.serialize(s),
Self::RawNumber(v) => v.serialize(s),
Self::RawText(v) => v.serialize(s),
}
}
}
impl FromWire for DataTableCell {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.get("type").and_then(Value::as_str) {
Some("rich_text") => RichTextBlock::from_wire(value, path).map(Into::into),
Some("raw_number") => RawNumber::from_wire(value, path).map(Into::into),
Some("raw_text") => RawText::from_wire(value, path).map(Into::into),
_ => Err(wire::mismatch(
&format!("{path}.type"),
"a DataTableCell discriminator",
)),
}
}
}
impl TryFrom<Value> for DataTableCell {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "DataTableCell")
}
}
impl<'de> Deserialize<'de> for DataTableCell {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl From<RichTextBlock> for DataTableCell {
fn from(value: RichTextBlock) -> Self {
Self::RichText(value)
}
}
impl From<RawNumber> for DataTableCell {
fn from(value: RawNumber) -> Self {
Self::RawNumber(value)
}
}
impl From<RawText> for DataTableCell {
fn from(value: RawText) -> Self {
Self::RawText(value)
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Element {
Button(Box<ButtonElement>),
ChannelMultiSelect(Box<ChannelMultiSelectElement>),
ChannelSelect(Box<ChannelSelectElement>),
Checkboxes(Box<CheckboxesElement>),
ConversationMultiSelect(Box<ConversationMultiSelectElement>),
ConversationSelect(Box<ConversationSelectElement>),
DatePicker(Box<DatePickerElement>),
DateTimePicker(Box<DateTimePickerElement>),
EmailInput(Box<EmailInputElement>),
ExternalMultiSelect(Box<ExternalMultiSelectElement>),
ExternalSelect(Box<ExternalSelectElement>),
FeedbackButtons(Box<FeedbackButtonsElement>),
FileInput(Box<FileInputElement>),
IconButton(Box<IconButtonElement>),
Image(Box<ImageElement>),
NumberInput(Box<NumberInputElement>),
Overflow(Box<OverflowElement>),
PlainTextInput(Box<PlainTextInputElement>),
RadioButtons(Box<RadioButtonsElement>),
RichTextInput(Box<RichTextInputElement>),
StaticMultiSelect(Box<StaticMultiSelectElement>),
StaticSelect(Box<StaticSelectElement>),
TimePicker(Box<TimePickerElement>),
UrlInput(Box<UrlInputElement>),
UserMultiSelect(Box<UserMultiSelectElement>),
UserSelect(Box<UserSelectElement>),
WorkflowButton(Box<WorkflowButtonElement>),
}
impl Serialize for Element {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
match self {
Self::Button(v) => v.serialize(s),
Self::ChannelMultiSelect(v) => v.serialize(s),
Self::ChannelSelect(v) => v.serialize(s),
Self::Checkboxes(v) => v.serialize(s),
Self::ConversationMultiSelect(v) => v.serialize(s),
Self::ConversationSelect(v) => v.serialize(s),
Self::DatePicker(v) => v.serialize(s),
Self::DateTimePicker(v) => v.serialize(s),
Self::EmailInput(v) => v.serialize(s),
Self::ExternalMultiSelect(v) => v.serialize(s),
Self::ExternalSelect(v) => v.serialize(s),
Self::FeedbackButtons(v) => v.serialize(s),
Self::FileInput(v) => v.serialize(s),
Self::IconButton(v) => v.serialize(s),
Self::Image(v) => v.serialize(s),
Self::NumberInput(v) => v.serialize(s),
Self::Overflow(v) => v.serialize(s),
Self::PlainTextInput(v) => v.serialize(s),
Self::RadioButtons(v) => v.serialize(s),
Self::RichTextInput(v) => v.serialize(s),
Self::StaticMultiSelect(v) => v.serialize(s),
Self::StaticSelect(v) => v.serialize(s),
Self::TimePicker(v) => v.serialize(s),
Self::UrlInput(v) => v.serialize(s),
Self::UserMultiSelect(v) => v.serialize(s),
Self::UserSelect(v) => v.serialize(s),
Self::WorkflowButton(v) => v.serialize(s),
}
}
}
impl FromWire for Element {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.get("type").and_then(Value::as_str) {
Some("button") => ButtonElement::from_wire(value, path).map(Into::into),
Some("multi_channels_select") => {
ChannelMultiSelectElement::from_wire(value, path).map(Into::into)
}
Some("channels_select") => ChannelSelectElement::from_wire(value, path).map(Into::into),
Some("checkboxes") => CheckboxesElement::from_wire(value, path).map(Into::into),
Some("multi_conversations_select") => {
ConversationMultiSelectElement::from_wire(value, path).map(Into::into)
}
Some("conversations_select") => {
ConversationSelectElement::from_wire(value, path).map(Into::into)
}
Some("datepicker") => DatePickerElement::from_wire(value, path).map(Into::into),
Some("datetimepicker") => DateTimePickerElement::from_wire(value, path).map(Into::into),
Some("email_text_input") => EmailInputElement::from_wire(value, path).map(Into::into),
Some("multi_external_select") => {
ExternalMultiSelectElement::from_wire(value, path).map(Into::into)
}
Some("external_select") => {
ExternalSelectElement::from_wire(value, path).map(Into::into)
}
Some("feedback_buttons") => {
FeedbackButtonsElement::from_wire(value, path).map(Into::into)
}
Some("file_input") => FileInputElement::from_wire(value, path).map(Into::into),
Some("icon_button") => IconButtonElement::from_wire(value, path).map(Into::into),
Some("image") => ImageElement::from_wire(value, path).map(Into::into),
Some("number_input") => NumberInputElement::from_wire(value, path).map(Into::into),
Some("overflow") => OverflowElement::from_wire(value, path).map(Into::into),
Some("plain_text_input") => {
PlainTextInputElement::from_wire(value, path).map(Into::into)
}
Some("radio_buttons") => RadioButtonsElement::from_wire(value, path).map(Into::into),
Some("rich_text_input") => RichTextInputElement::from_wire(value, path).map(Into::into),
Some("multi_static_select") => {
StaticMultiSelectElement::from_wire(value, path).map(Into::into)
}
Some("static_select") => StaticSelectElement::from_wire(value, path).map(Into::into),
Some("timepicker") => TimePickerElement::from_wire(value, path).map(Into::into),
Some("url_text_input") => UrlInputElement::from_wire(value, path).map(Into::into),
Some("multi_users_select") => {
UserMultiSelectElement::from_wire(value, path).map(Into::into)
}
Some("users_select") => UserSelectElement::from_wire(value, path).map(Into::into),
Some("workflow_button") => {
WorkflowButtonElement::from_wire(value, path).map(Into::into)
}
_ => Err(wire::mismatch(
&format!("{path}.type"),
"a Element discriminator",
)),
}
}
}
impl TryFrom<Value> for Element {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "Element")
}
}
impl<'de> Deserialize<'de> for Element {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl From<ButtonElement> for Element {
fn from(value: ButtonElement) -> Self {
Self::Button(Box::new(value))
}
}
impl From<ChannelMultiSelectElement> for Element {
fn from(value: ChannelMultiSelectElement) -> Self {
Self::ChannelMultiSelect(Box::new(value))
}
}
impl From<ChannelSelectElement> for Element {
fn from(value: ChannelSelectElement) -> Self {
Self::ChannelSelect(Box::new(value))
}
}
impl From<CheckboxesElement> for Element {
fn from(value: CheckboxesElement) -> Self {
Self::Checkboxes(Box::new(value))
}
}
impl From<ConversationMultiSelectElement> for Element {
fn from(value: ConversationMultiSelectElement) -> Self {
Self::ConversationMultiSelect(Box::new(value))
}
}
impl From<ConversationSelectElement> for Element {
fn from(value: ConversationSelectElement) -> Self {
Self::ConversationSelect(Box::new(value))
}
}
impl From<DatePickerElement> for Element {
fn from(value: DatePickerElement) -> Self {
Self::DatePicker(Box::new(value))
}
}
impl From<DateTimePickerElement> for Element {
fn from(value: DateTimePickerElement) -> Self {
Self::DateTimePicker(Box::new(value))
}
}
impl From<EmailInputElement> for Element {
fn from(value: EmailInputElement) -> Self {
Self::EmailInput(Box::new(value))
}
}
impl From<ExternalMultiSelectElement> for Element {
fn from(value: ExternalMultiSelectElement) -> Self {
Self::ExternalMultiSelect(Box::new(value))
}
}
impl From<ExternalSelectElement> for Element {
fn from(value: ExternalSelectElement) -> Self {
Self::ExternalSelect(Box::new(value))
}
}
impl From<FeedbackButtonsElement> for Element {
fn from(value: FeedbackButtonsElement) -> Self {
Self::FeedbackButtons(Box::new(value))
}
}
impl From<FileInputElement> for Element {
fn from(value: FileInputElement) -> Self {
Self::FileInput(Box::new(value))
}
}
impl From<IconButtonElement> for Element {
fn from(value: IconButtonElement) -> Self {
Self::IconButton(Box::new(value))
}
}
impl From<ImageElement> for Element {
fn from(value: ImageElement) -> Self {
Self::Image(Box::new(value))
}
}
impl From<NumberInputElement> for Element {
fn from(value: NumberInputElement) -> Self {
Self::NumberInput(Box::new(value))
}
}
impl From<OverflowElement> for Element {
fn from(value: OverflowElement) -> Self {
Self::Overflow(Box::new(value))
}
}
impl From<PlainTextInputElement> for Element {
fn from(value: PlainTextInputElement) -> Self {
Self::PlainTextInput(Box::new(value))
}
}
impl From<RadioButtonsElement> for Element {
fn from(value: RadioButtonsElement) -> Self {
Self::RadioButtons(Box::new(value))
}
}
impl From<RichTextInputElement> for Element {
fn from(value: RichTextInputElement) -> Self {
Self::RichTextInput(Box::new(value))
}
}
impl From<StaticMultiSelectElement> for Element {
fn from(value: StaticMultiSelectElement) -> Self {
Self::StaticMultiSelect(Box::new(value))
}
}
impl From<StaticSelectElement> for Element {
fn from(value: StaticSelectElement) -> Self {
Self::StaticSelect(Box::new(value))
}
}
impl From<TimePickerElement> for Element {
fn from(value: TimePickerElement) -> Self {
Self::TimePicker(Box::new(value))
}
}
impl From<UrlInputElement> for Element {
fn from(value: UrlInputElement) -> Self {
Self::UrlInput(Box::new(value))
}
}
impl From<UserMultiSelectElement> for Element {
fn from(value: UserMultiSelectElement) -> Self {
Self::UserMultiSelect(Box::new(value))
}
}
impl From<UserSelectElement> for Element {
fn from(value: UserSelectElement) -> Self {
Self::UserSelect(Box::new(value))
}
}
impl From<WorkflowButtonElement> for Element {
fn from(value: WorkflowButtonElement) -> Self {
Self::WorkflowButton(Box::new(value))
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum InputElement {
ChannelMultiSelect(Box<ChannelMultiSelectElement>),
ChannelSelect(Box<ChannelSelectElement>),
Checkboxes(Box<CheckboxesElement>),
ConversationMultiSelect(Box<ConversationMultiSelectElement>),
ConversationSelect(Box<ConversationSelectElement>),
DatePicker(Box<DatePickerElement>),
DateTimePicker(Box<DateTimePickerElement>),
EmailInput(Box<EmailInputElement>),
ExternalMultiSelect(Box<ExternalMultiSelectElement>),
ExternalSelect(Box<ExternalSelectElement>),
FileInput(Box<FileInputElement>),
NumberInput(Box<NumberInputElement>),
PlainTextInput(Box<PlainTextInputElement>),
RadioButtons(Box<RadioButtonsElement>),
RichTextInput(Box<RichTextInputElement>),
StaticMultiSelect(Box<StaticMultiSelectElement>),
StaticSelect(Box<StaticSelectElement>),
TimePicker(Box<TimePickerElement>),
UrlInput(Box<UrlInputElement>),
UserMultiSelect(Box<UserMultiSelectElement>),
UserSelect(Box<UserSelectElement>),
}
impl Serialize for InputElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
match self {
Self::ChannelMultiSelect(v) => v.serialize(s),
Self::ChannelSelect(v) => v.serialize(s),
Self::Checkboxes(v) => v.serialize(s),
Self::ConversationMultiSelect(v) => v.serialize(s),
Self::ConversationSelect(v) => v.serialize(s),
Self::DatePicker(v) => v.serialize(s),
Self::DateTimePicker(v) => v.serialize(s),
Self::EmailInput(v) => v.serialize(s),
Self::ExternalMultiSelect(v) => v.serialize(s),
Self::ExternalSelect(v) => v.serialize(s),
Self::FileInput(v) => v.serialize(s),
Self::NumberInput(v) => v.serialize(s),
Self::PlainTextInput(v) => v.serialize(s),
Self::RadioButtons(v) => v.serialize(s),
Self::RichTextInput(v) => v.serialize(s),
Self::StaticMultiSelect(v) => v.serialize(s),
Self::StaticSelect(v) => v.serialize(s),
Self::TimePicker(v) => v.serialize(s),
Self::UrlInput(v) => v.serialize(s),
Self::UserMultiSelect(v) => v.serialize(s),
Self::UserSelect(v) => v.serialize(s),
}
}
}
impl FromWire for InputElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.get("type").and_then(Value::as_str) {
Some("multi_channels_select") => {
ChannelMultiSelectElement::from_wire(value, path).map(Into::into)
}
Some("channels_select") => ChannelSelectElement::from_wire(value, path).map(Into::into),
Some("checkboxes") => CheckboxesElement::from_wire(value, path).map(Into::into),
Some("multi_conversations_select") => {
ConversationMultiSelectElement::from_wire(value, path).map(Into::into)
}
Some("conversations_select") => {
ConversationSelectElement::from_wire(value, path).map(Into::into)
}
Some("datepicker") => DatePickerElement::from_wire(value, path).map(Into::into),
Some("datetimepicker") => DateTimePickerElement::from_wire(value, path).map(Into::into),
Some("email_text_input") => EmailInputElement::from_wire(value, path).map(Into::into),
Some("multi_external_select") => {
ExternalMultiSelectElement::from_wire(value, path).map(Into::into)
}
Some("external_select") => {
ExternalSelectElement::from_wire(value, path).map(Into::into)
}
Some("file_input") => FileInputElement::from_wire(value, path).map(Into::into),
Some("number_input") => NumberInputElement::from_wire(value, path).map(Into::into),
Some("plain_text_input") => {
PlainTextInputElement::from_wire(value, path).map(Into::into)
}
Some("radio_buttons") => RadioButtonsElement::from_wire(value, path).map(Into::into),
Some("rich_text_input") => RichTextInputElement::from_wire(value, path).map(Into::into),
Some("multi_static_select") => {
StaticMultiSelectElement::from_wire(value, path).map(Into::into)
}
Some("static_select") => StaticSelectElement::from_wire(value, path).map(Into::into),
Some("timepicker") => TimePickerElement::from_wire(value, path).map(Into::into),
Some("url_text_input") => UrlInputElement::from_wire(value, path).map(Into::into),
Some("multi_users_select") => {
UserMultiSelectElement::from_wire(value, path).map(Into::into)
}
Some("users_select") => UserSelectElement::from_wire(value, path).map(Into::into),
_ => Err(wire::mismatch(
&format!("{path}.type"),
"a InputElement discriminator",
)),
}
}
}
impl TryFrom<Value> for InputElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "InputElement")
}
}
impl<'de> Deserialize<'de> for InputElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl From<ChannelMultiSelectElement> for InputElement {
fn from(value: ChannelMultiSelectElement) -> Self {
Self::ChannelMultiSelect(Box::new(value))
}
}
impl From<ChannelSelectElement> for InputElement {
fn from(value: ChannelSelectElement) -> Self {
Self::ChannelSelect(Box::new(value))
}
}
impl From<CheckboxesElement> for InputElement {
fn from(value: CheckboxesElement) -> Self {
Self::Checkboxes(Box::new(value))
}
}
impl From<ConversationMultiSelectElement> for InputElement {
fn from(value: ConversationMultiSelectElement) -> Self {
Self::ConversationMultiSelect(Box::new(value))
}
}
impl From<ConversationSelectElement> for InputElement {
fn from(value: ConversationSelectElement) -> Self {
Self::ConversationSelect(Box::new(value))
}
}
impl From<DatePickerElement> for InputElement {
fn from(value: DatePickerElement) -> Self {
Self::DatePicker(Box::new(value))
}
}
impl From<DateTimePickerElement> for InputElement {
fn from(value: DateTimePickerElement) -> Self {
Self::DateTimePicker(Box::new(value))
}
}
impl From<EmailInputElement> for InputElement {
fn from(value: EmailInputElement) -> Self {
Self::EmailInput(Box::new(value))
}
}
impl From<ExternalMultiSelectElement> for InputElement {
fn from(value: ExternalMultiSelectElement) -> Self {
Self::ExternalMultiSelect(Box::new(value))
}
}
impl From<ExternalSelectElement> for InputElement {
fn from(value: ExternalSelectElement) -> Self {
Self::ExternalSelect(Box::new(value))
}
}
impl From<FileInputElement> for InputElement {
fn from(value: FileInputElement) -> Self {
Self::FileInput(Box::new(value))
}
}
impl From<NumberInputElement> for InputElement {
fn from(value: NumberInputElement) -> Self {
Self::NumberInput(Box::new(value))
}
}
impl From<PlainTextInputElement> for InputElement {
fn from(value: PlainTextInputElement) -> Self {
Self::PlainTextInput(Box::new(value))
}
}
impl From<RadioButtonsElement> for InputElement {
fn from(value: RadioButtonsElement) -> Self {
Self::RadioButtons(Box::new(value))
}
}
impl From<RichTextInputElement> for InputElement {
fn from(value: RichTextInputElement) -> Self {
Self::RichTextInput(Box::new(value))
}
}
impl From<StaticMultiSelectElement> for InputElement {
fn from(value: StaticMultiSelectElement) -> Self {
Self::StaticMultiSelect(Box::new(value))
}
}
impl From<StaticSelectElement> for InputElement {
fn from(value: StaticSelectElement) -> Self {
Self::StaticSelect(Box::new(value))
}
}
impl From<TimePickerElement> for InputElement {
fn from(value: TimePickerElement) -> Self {
Self::TimePicker(Box::new(value))
}
}
impl From<UrlInputElement> for InputElement {
fn from(value: UrlInputElement) -> Self {
Self::UrlInput(Box::new(value))
}
}
impl From<UserMultiSelectElement> for InputElement {
fn from(value: UserMultiSelectElement) -> Self {
Self::UserMultiSelect(Box::new(value))
}
}
impl From<UserSelectElement> for InputElement {
fn from(value: UserSelectElement) -> Self {
Self::UserSelect(Box::new(value))
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Text {
Markdown(MarkdownText),
Plain(PlainText),
}
impl Serialize for Text {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
match self {
Self::Markdown(v) => v.serialize(s),
Self::Plain(v) => v.serialize(s),
}
}
}
impl FromWire for Text {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.get("type").and_then(Value::as_str) {
Some("mrkdwn") => MarkdownText::from_wire(value, path).map(Into::into),
Some("plain_text") => PlainText::from_wire(value, path).map(Into::into),
_ => Err(wire::mismatch(
&format!("{path}.type"),
"a Text discriminator",
)),
}
}
}
impl TryFrom<Value> for Text {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "Text")
}
}
impl<'de> Deserialize<'de> for Text {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl From<MarkdownText> for Text {
fn from(value: MarkdownText) -> Self {
Self::Markdown(value)
}
}
impl From<PlainText> for Text {
fn from(value: PlainText) -> Self {
Self::Plain(value)
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Chart {
Area(AreaChart),
Bar(BarChart),
Line(LineChart),
Pie(PieChart),
}
impl Serialize for Chart {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
match self {
Self::Area(v) => v.serialize(s),
Self::Bar(v) => v.serialize(s),
Self::Line(v) => v.serialize(s),
Self::Pie(v) => v.serialize(s),
}
}
}
impl FromWire for Chart {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.get("type").and_then(Value::as_str) {
Some("area") => AreaChart::from_wire(value, path).map(Into::into),
Some("bar") => BarChart::from_wire(value, path).map(Into::into),
Some("line") => LineChart::from_wire(value, path).map(Into::into),
Some("pie") => PieChart::from_wire(value, path).map(Into::into),
_ => Err(wire::mismatch(
&format!("{path}.type"),
"a Chart discriminator",
)),
}
}
}
impl TryFrom<Value> for Chart {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "Chart")
}
}
impl<'de> Deserialize<'de> for Chart {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl From<AreaChart> for Chart {
fn from(value: AreaChart) -> Self {
Self::Area(value)
}
}
impl From<BarChart> for Chart {
fn from(value: BarChart) -> Self {
Self::Bar(value)
}
}
impl From<LineChart> for Chart {
fn from(value: LineChart) -> Self {
Self::Line(value)
}
}
impl From<PieChart> for Chart {
fn from(value: PieChart) -> Self {
Self::Pie(value)
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum RichTextBlockElement {
CodeBlock(RichTextCodeBlock),
List(RichTextList),
Quote(RichTextQuote),
Section(RichTextSection),
}
impl Serialize for RichTextBlockElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
match self {
Self::CodeBlock(v) => v.serialize(s),
Self::List(v) => v.serialize(s),
Self::Quote(v) => v.serialize(s),
Self::Section(v) => v.serialize(s),
}
}
}
impl FromWire for RichTextBlockElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.get("type").and_then(Value::as_str) {
Some("rich_text_preformatted") => {
RichTextCodeBlock::from_wire(value, path).map(Into::into)
}
Some("rich_text_list") => RichTextList::from_wire(value, path).map(Into::into),
Some("rich_text_quote") => RichTextQuote::from_wire(value, path).map(Into::into),
Some("rich_text_section") => RichTextSection::from_wire(value, path).map(Into::into),
_ => Err(wire::mismatch(
&format!("{path}.type"),
"a RichTextBlockElement discriminator",
)),
}
}
}
impl TryFrom<Value> for RichTextBlockElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextBlockElement")
}
}
impl<'de> Deserialize<'de> for RichTextBlockElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl From<RichTextCodeBlock> for RichTextBlockElement {
fn from(value: RichTextCodeBlock) -> Self {
Self::CodeBlock(value)
}
}
impl From<RichTextList> for RichTextBlockElement {
fn from(value: RichTextList) -> Self {
Self::List(value)
}
}
impl From<RichTextQuote> for RichTextBlockElement {
fn from(value: RichTextQuote) -> Self {
Self::Quote(value)
}
}
impl From<RichTextSection> for RichTextBlockElement {
fn from(value: RichTextSection) -> Self {
Self::Section(value)
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum RichTextSectionElement {
Channel(RichTextChannel),
Emoji(RichTextEmoji),
Link(RichTextLink),
Text(RichTextText),
User(RichTextUser),
UserGroup(RichTextUserGroup),
}
impl Serialize for RichTextSectionElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
match self {
Self::Channel(v) => v.serialize(s),
Self::Emoji(v) => v.serialize(s),
Self::Link(v) => v.serialize(s),
Self::Text(v) => v.serialize(s),
Self::User(v) => v.serialize(s),
Self::UserGroup(v) => v.serialize(s),
}
}
}
impl FromWire for RichTextSectionElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
match value.get("type").and_then(Value::as_str) {
Some("channel") => RichTextChannel::from_wire(value, path).map(Into::into),
Some("emoji") => RichTextEmoji::from_wire(value, path).map(Into::into),
Some("link") => RichTextLink::from_wire(value, path).map(Into::into),
Some("text") => RichTextText::from_wire(value, path).map(Into::into),
Some("user") => RichTextUser::from_wire(value, path).map(Into::into),
Some("usergroup") => RichTextUserGroup::from_wire(value, path).map(Into::into),
_ => Err(wire::mismatch(
&format!("{path}.type"),
"a RichTextSectionElement discriminator",
)),
}
}
}
impl TryFrom<Value> for RichTextSectionElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextSectionElement")
}
}
impl<'de> Deserialize<'de> for RichTextSectionElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
impl From<RichTextChannel> for RichTextSectionElement {
fn from(value: RichTextChannel) -> Self {
Self::Channel(value)
}
}
impl From<RichTextEmoji> for RichTextSectionElement {
fn from(value: RichTextEmoji) -> Self {
Self::Emoji(value)
}
}
impl From<RichTextLink> for RichTextSectionElement {
fn from(value: RichTextLink) -> Self {
Self::Link(value)
}
}
impl From<RichTextText> for RichTextSectionElement {
fn from(value: RichTextText) -> Self {
Self::Text(value)
}
}
impl From<RichTextUser> for RichTextSectionElement {
fn from(value: RichTextUser) -> Self {
Self::User(value)
}
}
impl From<RichTextUserGroup> for RichTextSectionElement {
fn from(value: RichTextUserGroup) -> Self {
Self::UserGroup(value)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ActionsBlock {
elements: Vec<Element>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ActionsBlockBuilder {
elements: Option<Vec<Element>>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for ActionsBlockBuilder {
fn default() -> Self {
Self {
elements: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl ActionsBlock {
pub fn builder() -> ActionsBlockBuilder {
ActionsBlockBuilder::default()
}
pub fn into_builder(self) -> ActionsBlockBuilder {
ActionsBlockBuilder {
elements: Some(self.elements),
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn elements(&self) -> &[Element] {
&self.elements
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "actions")?;
map.serialize_entry("elements", &self.elements)?;
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ActionsBlockBuilder {
pub fn elements<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<Element>,
{
self.elements = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn element(mut self, value: impl Into<Element>) -> Self {
self.elements
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ActionsBlock, ValidationError> {
let elements = wire::required(self.elements, "ActionsBlock.elements")?;
let block_id = self.block_id;
wire::extensions(&self.extensions, &["elements", "block_id"], "ActionsBlock")?;
let value = ActionsBlock {
elements,
block_id,
extensions: self.extensions,
};
{
let v = &value.elements;
crate::rules::length(v.len(), None, Some(25), "ActionsBlock.elements")?;
}
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "ActionsBlock.block_id")?;
}
Ok(value)
}
}
impl Serialize for ActionsBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ActionsBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "actions", path)?;
let elements = wire::field::<Vec<Element>>(&mut map, "elements", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
ActionsBlockBuilder {
elements,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ActionsBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ActionsBlock")
}
}
impl<'de> Deserialize<'de> for ActionsBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct AlertBlock {
text: Text,
level: Option<AlertLevel>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct AlertBlockBuilder {
text: Option<TextInput>,
level: Option<AlertLevel>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for AlertBlockBuilder {
fn default() -> Self {
Self {
text: None,
level: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl AlertBlock {
pub fn builder() -> AlertBlockBuilder {
AlertBlockBuilder::default()
}
pub fn into_builder(self) -> AlertBlockBuilder {
AlertBlockBuilder {
text: Some(self.text.into()),
level: self.level,
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn text(&self) -> &Text {
&self.text
}
pub fn level(&self) -> Option<AlertLevel> {
self.level
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "alert")?;
map.serialize_entry("text", &self.text)?;
if let Some(value) = &self.level {
map.serialize_entry("level", value)?;
}
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl AlertBlockBuilder {
pub fn text(mut self, value: impl Into<TextInput>) -> Self {
self.text = Some(value.into());
self
}
pub fn level(mut self, value: AlertLevel) -> Self {
self.level = Some(value);
self
}
pub fn clear_level(mut self) -> Self {
self.level = None;
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<AlertBlock, ValidationError> {
let text = wire::required(
self.text
.map(|v| v.resolve(false).map_err(|e| e.at("AlertBlock.text")))
.transpose()?,
"AlertBlock.text",
)?;
let level = self.level;
let block_id = self.block_id;
wire::extensions(
&self.extensions,
&["text", "level", "block_id"],
"AlertBlock",
)?;
let value = AlertBlock {
text,
level,
block_id,
extensions: self.extensions,
};
{
let v = &value.text;
crate::rules::length(
crate::rules::text_len(v),
None,
Some(200),
"AlertBlock.text",
)?;
}
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "AlertBlock.block_id")?;
}
Ok(value)
}
}
impl Serialize for AlertBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for AlertBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "alert", path)?;
crate::rules::coerce_text(map.get_mut("text"), "mrkdwn");
let text = wire::field::<Text>(&mut map, "text", path)?;
let level = wire::field::<AlertLevel>(&mut map, "level", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
AlertBlockBuilder {
text: text.map(Into::into),
level,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for AlertBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "AlertBlock")
}
}
impl<'de> Deserialize<'de> for AlertBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct CardBlock {
hero_image: Option<ImageElement>,
icon: Option<ImageElement>,
title: Option<Text>,
subtitle: Option<Text>,
body: Option<Text>,
actions: Option<Vec<ButtonElement>>,
slack_icon: Option<SlackIcon>,
subtext: Option<Text>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct CardBlockBuilder {
hero_image: Option<ImageElement>,
icon: Option<ImageElement>,
title: Option<TextInput>,
subtitle: Option<TextInput>,
body: Option<TextInput>,
actions: Option<Vec<ButtonElement>>,
slack_icon: Option<SlackIcon>,
subtext: Option<TextInput>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for CardBlockBuilder {
fn default() -> Self {
Self {
hero_image: None,
icon: None,
title: None,
subtitle: None,
body: None,
actions: None,
slack_icon: None,
subtext: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl CardBlock {
pub fn builder() -> CardBlockBuilder {
CardBlockBuilder::default()
}
pub fn into_builder(self) -> CardBlockBuilder {
CardBlockBuilder {
hero_image: self.hero_image,
icon: self.icon,
title: self.title.map(Into::into),
subtitle: self.subtitle.map(Into::into),
body: self.body.map(Into::into),
actions: self.actions,
slack_icon: self.slack_icon,
subtext: self.subtext.map(Into::into),
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn hero_image(&self) -> Option<&ImageElement> {
self.hero_image.as_ref()
}
pub fn icon(&self) -> Option<&ImageElement> {
self.icon.as_ref()
}
pub fn title(&self) -> Option<&Text> {
self.title.as_ref()
}
pub fn subtitle(&self) -> Option<&Text> {
self.subtitle.as_ref()
}
pub fn body(&self) -> Option<&Text> {
self.body.as_ref()
}
pub fn actions(&self) -> Option<&[ButtonElement]> {
self.actions.as_deref()
}
pub fn slack_icon(&self) -> Option<&SlackIcon> {
self.slack_icon.as_ref()
}
pub fn subtext(&self) -> Option<&Text> {
self.subtext.as_ref()
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "card")?;
if let Some(value) = &self.hero_image {
map.serialize_entry("hero_image", value)?;
}
if let Some(value) = &self.icon {
map.serialize_entry("icon", value)?;
}
if let Some(value) = &self.title {
map.serialize_entry("title", value)?;
}
if let Some(value) = &self.subtitle {
map.serialize_entry("subtitle", value)?;
}
if let Some(value) = &self.body {
map.serialize_entry("body", value)?;
}
if let Some(value) = &self.actions {
map.serialize_entry("actions", value)?;
}
if let Some(value) = &self.slack_icon {
map.serialize_entry("slack_icon", value)?;
}
if let Some(value) = &self.subtext {
map.serialize_entry("subtext", value)?;
}
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl CardBlockBuilder {
pub fn hero_image(mut self, value: impl Into<ImageElement>) -> Self {
self.hero_image = Some(value.into());
self
}
pub fn clear_hero_image(mut self) -> Self {
self.hero_image = None;
self
}
pub fn icon(mut self, value: impl Into<ImageElement>) -> Self {
self.icon = Some(value.into());
self
}
pub fn clear_icon(mut self) -> Self {
self.icon = None;
self
}
pub fn title(mut self, value: impl Into<TextInput>) -> Self {
self.title = Some(value.into());
self
}
pub fn clear_title(mut self) -> Self {
self.title = None;
self
}
pub fn subtitle(mut self, value: impl Into<TextInput>) -> Self {
self.subtitle = Some(value.into());
self
}
pub fn clear_subtitle(mut self) -> Self {
self.subtitle = None;
self
}
pub fn body(mut self, value: impl Into<TextInput>) -> Self {
self.body = Some(value.into());
self
}
pub fn clear_body(mut self) -> Self {
self.body = None;
self
}
pub fn actions<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<ButtonElement>,
{
self.actions = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn action(mut self, value: impl Into<ButtonElement>) -> Self {
self.actions.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn clear_actions(mut self) -> Self {
self.actions = None;
self
}
pub fn slack_icon(mut self, value: impl Into<SlackIcon>) -> Self {
self.slack_icon = Some(value.into());
self
}
pub fn clear_slack_icon(mut self) -> Self {
self.slack_icon = None;
self
}
pub fn subtext(mut self, value: impl Into<TextInput>) -> Self {
self.subtext = Some(value.into());
self
}
pub fn clear_subtext(mut self) -> Self {
self.subtext = None;
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<CardBlock, ValidationError> {
let hero_image = self.hero_image;
let icon = self.icon;
let title = self
.title
.map(|v| v.resolve(false).map_err(|e| e.at("CardBlock.title")))
.transpose()?;
let subtitle = self
.subtitle
.map(|v| v.resolve(false).map_err(|e| e.at("CardBlock.subtitle")))
.transpose()?;
let body = self
.body
.map(|v| v.resolve(false).map_err(|e| e.at("CardBlock.body")))
.transpose()?;
let actions = self.actions;
let slack_icon = self.slack_icon;
let subtext = self
.subtext
.map(|v| v.resolve(false).map_err(|e| e.at("CardBlock.subtext")))
.transpose()?;
let block_id = self.block_id;
wire::extensions(
&self.extensions,
&[
"hero_image",
"icon",
"title",
"subtitle",
"body",
"actions",
"slack_icon",
"subtext",
"block_id",
],
"CardBlock",
)?;
let value = CardBlock {
hero_image,
icon,
title,
subtitle,
body,
actions,
slack_icon,
subtext,
block_id,
extensions: self.extensions,
};
if let Some(v) = &value.title {
crate::rules::length(
crate::rules::text_len(v),
None,
Some(150),
"CardBlock.title",
)?;
}
if let Some(v) = &value.subtitle {
crate::rules::length(
crate::rules::text_len(v),
None,
Some(150),
"CardBlock.subtitle",
)?;
}
if let Some(v) = &value.body {
crate::rules::length(crate::rules::text_len(v), None, Some(200), "CardBlock.body")?;
}
if let Some(v) = &value.actions {
crate::rules::length(v.len(), None, Some(3), "CardBlock.actions")?;
}
if let Some(v) = &value.subtext {
crate::rules::length(
crate::rules::text_len(v),
None,
Some(200),
"CardBlock.subtext",
)?;
}
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "CardBlock.block_id")?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "CardBlock", e.to_string())
})?;
crate::rules::validate("CardBlock", &wire, "CardBlock")?;
Ok(value)
}
}
impl Serialize for CardBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for CardBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "card", path)?;
let hero_image = wire::field::<ImageElement>(&mut map, "hero_image", path)?;
let icon = wire::field::<ImageElement>(&mut map, "icon", path)?;
crate::rules::coerce_text(map.get_mut("title"), "mrkdwn");
let title = wire::field::<Text>(&mut map, "title", path)?;
crate::rules::coerce_text(map.get_mut("subtitle"), "mrkdwn");
let subtitle = wire::field::<Text>(&mut map, "subtitle", path)?;
crate::rules::coerce_text(map.get_mut("body"), "mrkdwn");
let body = wire::field::<Text>(&mut map, "body", path)?;
let actions = wire::field::<Vec<ButtonElement>>(&mut map, "actions", path)?;
let slack_icon = wire::field::<SlackIcon>(&mut map, "slack_icon", path)?;
crate::rules::coerce_text(map.get_mut("subtext"), "mrkdwn");
let subtext = wire::field::<Text>(&mut map, "subtext", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
CardBlockBuilder {
hero_image,
icon,
title: title.map(Into::into),
subtitle: subtitle.map(Into::into),
body: body.map(Into::into),
actions,
slack_icon,
subtext: subtext.map(Into::into),
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for CardBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "CardBlock")
}
}
impl<'de> Deserialize<'de> for CardBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct CarouselBlock {
elements: Vec<CardBlock>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct CarouselBlockBuilder {
elements: Option<Vec<CardBlock>>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for CarouselBlockBuilder {
fn default() -> Self {
Self {
elements: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl CarouselBlock {
pub fn builder() -> CarouselBlockBuilder {
CarouselBlockBuilder::default()
}
pub fn into_builder(self) -> CarouselBlockBuilder {
CarouselBlockBuilder {
elements: Some(self.elements),
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn elements(&self) -> &[CardBlock] {
&self.elements
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "carousel")?;
map.serialize_entry("elements", &self.elements)?;
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl CarouselBlockBuilder {
pub fn elements<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<CardBlock>,
{
self.elements = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn element(mut self, value: impl Into<CardBlock>) -> Self {
self.elements
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<CarouselBlock, ValidationError> {
let elements = wire::required(self.elements, "CarouselBlock.elements")?;
let block_id = self.block_id;
wire::extensions(&self.extensions, &["elements", "block_id"], "CarouselBlock")?;
let value = CarouselBlock {
elements,
block_id,
extensions: self.extensions,
};
{
let v = &value.elements;
crate::rules::length(v.len(), Some(1), Some(10), "CarouselBlock.elements")?;
}
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "CarouselBlock.block_id")?;
}
Ok(value)
}
}
impl Serialize for CarouselBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for CarouselBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "carousel", path)?;
let elements = wire::field::<Vec<CardBlock>>(&mut map, "elements", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
CarouselBlockBuilder {
elements,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for CarouselBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "CarouselBlock")
}
}
impl<'de> Deserialize<'de> for CarouselBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ContainerBlock {
child_blocks: Vec<Block>,
title: Option<PlainText>,
rich_text_title: Option<RichTextBlock>,
subtitle: Option<Text>,
width: Option<ContainerWidth>,
icon: Option<ImageElement>,
is_collapsible: Option<bool>,
default_collapsed: Option<bool>,
has_header_divider: Option<bool>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ContainerBlockBuilder {
child_blocks: Option<Vec<Block>>,
title: Option<PlainTextInput>,
rich_text_title: Option<RichTextBlock>,
subtitle: Option<TextInput>,
width: Option<ContainerWidth>,
icon: Option<ImageElement>,
is_collapsible: Option<bool>,
default_collapsed: Option<bool>,
has_header_divider: Option<bool>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for ContainerBlockBuilder {
fn default() -> Self {
Self {
child_blocks: None,
title: None,
rich_text_title: None,
subtitle: None,
width: None,
icon: None,
is_collapsible: None,
default_collapsed: None,
has_header_divider: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl ContainerBlock {
pub fn builder() -> ContainerBlockBuilder {
ContainerBlockBuilder::default()
}
pub fn into_builder(self) -> ContainerBlockBuilder {
ContainerBlockBuilder {
child_blocks: Some(self.child_blocks),
title: self.title.map(Into::into),
rich_text_title: self.rich_text_title,
subtitle: self.subtitle.map(Into::into),
width: self.width,
icon: self.icon,
is_collapsible: self.is_collapsible,
default_collapsed: self.default_collapsed,
has_header_divider: self.has_header_divider,
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn child_blocks(&self) -> &[Block] {
&self.child_blocks
}
pub fn title(&self) -> Option<&PlainText> {
self.title.as_ref()
}
pub fn rich_text_title(&self) -> Option<&RichTextBlock> {
self.rich_text_title.as_ref()
}
pub fn subtitle(&self) -> Option<&Text> {
self.subtitle.as_ref()
}
pub fn width(&self) -> Option<ContainerWidth> {
self.width
}
pub fn icon(&self) -> Option<&ImageElement> {
self.icon.as_ref()
}
pub fn is_collapsible(&self) -> Option<bool> {
self.is_collapsible
}
pub fn default_collapsed(&self) -> Option<bool> {
self.default_collapsed
}
pub fn has_header_divider(&self) -> Option<bool> {
self.has_header_divider
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "container")?;
map.serialize_entry("child_blocks", &self.child_blocks)?;
if let Some(value) = &self.title {
map.serialize_entry("title", value)?;
}
if let Some(value) = &self.rich_text_title {
map.serialize_entry("rich_text_title", value)?;
}
if let Some(value) = &self.subtitle {
map.serialize_entry("subtitle", value)?;
}
if let Some(value) = &self.width {
map.serialize_entry("width", value)?;
}
if let Some(value) = &self.icon {
map.serialize_entry("icon", value)?;
}
if let Some(value) = &self.is_collapsible {
map.serialize_entry("is_collapsible", value)?;
}
if let Some(value) = &self.default_collapsed {
map.serialize_entry("default_collapsed", value)?;
}
if let Some(value) = &self.has_header_divider {
map.serialize_entry("has_header_divider", value)?;
}
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ContainerBlockBuilder {
pub fn child_blocks<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<Block>,
{
self.child_blocks = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn child_block(mut self, value: impl Into<Block>) -> Self {
self.child_blocks
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn title(mut self, value: impl Into<PlainTextInput>) -> Self {
self.title = Some(value.into());
self
}
pub fn clear_title(mut self) -> Self {
self.title = None;
self
}
pub fn rich_text_title(mut self, value: impl Into<RichTextBlock>) -> Self {
self.rich_text_title = Some(value.into());
self
}
pub fn clear_rich_text_title(mut self) -> Self {
self.rich_text_title = None;
self
}
pub fn subtitle(mut self, value: impl Into<TextInput>) -> Self {
self.subtitle = Some(value.into());
self
}
pub fn clear_subtitle(mut self) -> Self {
self.subtitle = None;
self
}
pub fn width(mut self, value: ContainerWidth) -> Self {
self.width = Some(value);
self
}
pub fn clear_width(mut self) -> Self {
self.width = None;
self
}
pub fn icon(mut self, value: impl Into<ImageElement>) -> Self {
self.icon = Some(value.into());
self
}
pub fn clear_icon(mut self) -> Self {
self.icon = None;
self
}
pub fn is_collapsible(mut self, value: bool) -> Self {
self.is_collapsible = Some(value);
self
}
pub fn clear_is_collapsible(mut self) -> Self {
self.is_collapsible = None;
self
}
pub fn default_collapsed(mut self, value: bool) -> Self {
self.default_collapsed = Some(value);
self
}
pub fn clear_default_collapsed(mut self) -> Self {
self.default_collapsed = None;
self
}
pub fn has_header_divider(mut self, value: bool) -> Self {
self.has_header_divider = Some(value);
self
}
pub fn clear_has_header_divider(mut self) -> Self {
self.has_header_divider = None;
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ContainerBlock, ValidationError> {
let child_blocks = wire::required(self.child_blocks, "ContainerBlock.child_blocks")?;
let title = self
.title
.map(|v| v.resolve().map_err(|e| e.at("ContainerBlock.title")))
.transpose()?;
let rich_text_title = self.rich_text_title;
let subtitle = self
.subtitle
.map(|v| {
v.resolve(false)
.map_err(|e| e.at("ContainerBlock.subtitle"))
})
.transpose()?;
let width = self.width;
let icon = self.icon;
let is_collapsible = self.is_collapsible;
let default_collapsed = self.default_collapsed;
let has_header_divider = self.has_header_divider;
let block_id = self.block_id;
wire::extensions(
&self.extensions,
&[
"child_blocks",
"title",
"rich_text_title",
"subtitle",
"width",
"icon",
"is_collapsible",
"default_collapsed",
"has_header_divider",
"block_id",
],
"ContainerBlock",
)?;
let value = ContainerBlock {
child_blocks,
title,
rich_text_title,
subtitle,
width,
icon,
is_collapsible,
default_collapsed,
has_header_divider,
block_id,
extensions: self.extensions,
};
{
let v = &value.child_blocks;
crate::rules::length(v.len(), Some(1), Some(10), "ContainerBlock.child_blocks")?;
}
if let Some(v) = &value.title {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"ContainerBlock.title",
)?;
}
if let Some(v) = &value.subtitle {
crate::rules::length(
crate::rules::text_len(v),
None,
Some(150),
"ContainerBlock.subtitle",
)?;
}
if let Some(v) = &value.block_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"ContainerBlock.block_id",
)?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "ContainerBlock", e.to_string())
})?;
crate::rules::validate("ContainerBlock", &wire, "ContainerBlock")?;
Ok(value)
}
}
impl Serialize for ContainerBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ContainerBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "container", path)?;
let child_blocks = wire::field::<Vec<Block>>(&mut map, "child_blocks", path)?;
crate::rules::coerce_text(map.get_mut("title"), "plain_text");
let title = wire::field::<PlainText>(&mut map, "title", path)?;
let rich_text_title = wire::field::<RichTextBlock>(&mut map, "rich_text_title", path)?;
crate::rules::coerce_text(map.get_mut("subtitle"), "mrkdwn");
let subtitle = wire::field::<Text>(&mut map, "subtitle", path)?;
let width = wire::field::<ContainerWidth>(&mut map, "width", path)?;
let icon = wire::field::<ImageElement>(&mut map, "icon", path)?;
let is_collapsible = wire::field::<bool>(&mut map, "is_collapsible", path)?;
let default_collapsed = wire::field::<bool>(&mut map, "default_collapsed", path)?;
let has_header_divider = wire::field::<bool>(&mut map, "has_header_divider", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
ContainerBlockBuilder {
child_blocks,
title: title.map(Into::into),
rich_text_title,
subtitle: subtitle.map(Into::into),
width,
icon,
is_collapsible,
default_collapsed,
has_header_divider,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ContainerBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ContainerBlock")
}
}
impl<'de> Deserialize<'de> for ContainerBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ContextActionsBlock {
elements: Vec<ContextActionsElement>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ContextActionsBlockBuilder {
elements: Option<Vec<ContextActionsElement>>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for ContextActionsBlockBuilder {
fn default() -> Self {
Self {
elements: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl ContextActionsBlock {
pub fn builder() -> ContextActionsBlockBuilder {
ContextActionsBlockBuilder::default()
}
pub fn into_builder(self) -> ContextActionsBlockBuilder {
ContextActionsBlockBuilder {
elements: Some(self.elements),
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn elements(&self) -> &[ContextActionsElement] {
&self.elements
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "context_actions")?;
map.serialize_entry("elements", &self.elements)?;
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ContextActionsBlockBuilder {
pub fn elements<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<ContextActionsElement>,
{
self.elements = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn element(mut self, value: impl Into<ContextActionsElement>) -> Self {
self.elements
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ContextActionsBlock, ValidationError> {
let elements = wire::required(self.elements, "ContextActionsBlock.elements")?;
let block_id = self.block_id;
wire::extensions(
&self.extensions,
&["elements", "block_id"],
"ContextActionsBlock",
)?;
let value = ContextActionsBlock {
elements,
block_id,
extensions: self.extensions,
};
{
let v = &value.elements;
crate::rules::length(v.len(), None, Some(5), "ContextActionsBlock.elements")?;
}
if let Some(v) = &value.block_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"ContextActionsBlock.block_id",
)?;
}
Ok(value)
}
}
impl Serialize for ContextActionsBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ContextActionsBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "context_actions", path)?;
let elements = wire::field::<Vec<ContextActionsElement>>(&mut map, "elements", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
ContextActionsBlockBuilder {
elements,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ContextActionsBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ContextActionsBlock")
}
}
impl<'de> Deserialize<'de> for ContextActionsBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ContextBlock {
elements: Vec<ContextElement>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ContextBlockBuilder {
elements: Option<Vec<ContextElement>>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for ContextBlockBuilder {
fn default() -> Self {
Self {
elements: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl ContextBlock {
pub fn builder() -> ContextBlockBuilder {
ContextBlockBuilder::default()
}
pub fn into_builder(self) -> ContextBlockBuilder {
ContextBlockBuilder {
elements: Some(self.elements),
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn elements(&self) -> &[ContextElement] {
&self.elements
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "context")?;
map.serialize_entry("elements", &self.elements)?;
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ContextBlockBuilder {
pub fn elements<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<ContextElement>,
{
self.elements = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn element(mut self, value: impl Into<ContextElement>) -> Self {
self.elements
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ContextBlock, ValidationError> {
let elements = wire::required(self.elements, "ContextBlock.elements")?;
let block_id = self.block_id;
wire::extensions(&self.extensions, &["elements", "block_id"], "ContextBlock")?;
let value = ContextBlock {
elements,
block_id,
extensions: self.extensions,
};
{
let v = &value.elements;
crate::rules::length(v.len(), None, Some(10), "ContextBlock.elements")?;
}
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "ContextBlock.block_id")?;
}
Ok(value)
}
}
impl Serialize for ContextBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ContextBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "context", path)?;
let elements = wire::field::<Vec<ContextElement>>(&mut map, "elements", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
ContextBlockBuilder {
elements,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ContextBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ContextBlock")
}
}
impl<'de> Deserialize<'de> for ContextBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct DataTableBlock {
rows: Vec<Vec<DataTableCell>>,
caption: String,
page_size: Option<i64>,
row_header_column_index: Option<i64>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct DataTableBlockBuilder {
rows: Option<Vec<Vec<DataTableCell>>>,
caption: Option<String>,
page_size: Option<i64>,
row_header_column_index: Option<i64>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for DataTableBlockBuilder {
fn default() -> Self {
Self {
rows: None,
caption: None,
page_size: Some(5),
row_header_column_index: Some(0),
block_id: None,
extensions: Map::new(),
}
}
}
impl DataTableBlock {
pub fn builder() -> DataTableBlockBuilder {
DataTableBlockBuilder::default()
}
pub fn into_builder(self) -> DataTableBlockBuilder {
DataTableBlockBuilder {
rows: Some(self.rows),
caption: Some(self.caption),
page_size: self.page_size,
row_header_column_index: self.row_header_column_index,
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn rows(&self) -> &[Vec<DataTableCell>] {
&self.rows
}
pub fn caption(&self) -> &str {
&self.caption
}
pub fn page_size(&self) -> Option<i64> {
self.page_size
}
pub fn row_header_column_index(&self) -> Option<i64> {
self.row_header_column_index
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "data_table")?;
map.serialize_entry("rows", &self.rows)?;
map.serialize_entry("caption", &self.caption)?;
if let Some(value) = &self.page_size {
map.serialize_entry("page_size", value)?;
}
if let Some(value) = &self.row_header_column_index {
map.serialize_entry("row_header_column_index", value)?;
}
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl DataTableBlockBuilder {
pub fn rows<I, R, T>(mut self, rows: I) -> Self
where
I: IntoIterator<Item = R>,
R: IntoIterator<Item = T>,
T: Into<DataTableCell>,
{
self.rows = Some(
rows.into_iter()
.map(|r| r.into_iter().map(Into::into).collect())
.collect(),
);
self
}
pub fn row<I, T>(mut self, row: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<DataTableCell>,
{
self.rows
.get_or_insert_with(Vec::new)
.push(row.into_iter().map(Into::into).collect());
self
}
pub fn caption(mut self, value: impl Into<String>) -> Self {
self.caption = Some(value.into());
self
}
pub fn page_size(mut self, value: i64) -> Self {
self.page_size = Some(value);
self
}
pub fn clear_page_size(mut self) -> Self {
self.page_size = None;
self
}
pub fn row_header_column_index(mut self, value: i64) -> Self {
self.row_header_column_index = Some(value);
self
}
pub fn clear_row_header_column_index(mut self) -> Self {
self.row_header_column_index = None;
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<DataTableBlock, ValidationError> {
let rows = wire::required(self.rows, "DataTableBlock.rows")?;
let caption = wire::required(self.caption, "DataTableBlock.caption")?;
let page_size = self.page_size;
let row_header_column_index = self.row_header_column_index;
let block_id = self.block_id;
wire::extensions(
&self.extensions,
&[
"rows",
"caption",
"page_size",
"row_header_column_index",
"block_id",
],
"DataTableBlock",
)?;
let value = DataTableBlock {
rows,
caption,
page_size,
row_header_column_index,
block_id,
extensions: self.extensions,
};
{
let v = &value.rows;
crate::rules::length(v.len(), Some(2), Some(201), "DataTableBlock.rows")?;
}
if let Some(v) = &value.page_size {
if *v < 1 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"DataTableBlock.page_size",
"number outside field bounds",
));
}
if *v > 100 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"DataTableBlock.page_size",
"number outside field bounds",
));
}
}
if let Some(v) = &value.row_header_column_index {
if *v < 0 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"DataTableBlock.row_header_column_index",
"number outside field bounds",
));
}
}
if let Some(v) = &value.block_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"DataTableBlock.block_id",
)?;
}
crate::rules::data_table(&value, "DataTableBlock")?;
Ok(value)
}
}
impl Serialize for DataTableBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for DataTableBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "data_table", path)?;
let rows = wire::field::<Vec<Vec<DataTableCell>>>(&mut map, "rows", path)?;
let caption = wire::field::<String>(&mut map, "caption", path)?;
let page_size = wire::field::<i64>(&mut map, "page_size", path)?;
let row_header_column_index =
wire::field::<i64>(&mut map, "row_header_column_index", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
DataTableBlockBuilder {
rows,
caption,
page_size,
row_header_column_index,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for DataTableBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "DataTableBlock")
}
}
impl<'de> Deserialize<'de> for DataTableBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct DataVisualizationBlock {
title: String,
chart: Chart,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct DataVisualizationBlockBuilder {
title: Option<String>,
chart: Option<Chart>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for DataVisualizationBlockBuilder {
fn default() -> Self {
Self {
title: None,
chart: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl DataVisualizationBlock {
pub fn builder() -> DataVisualizationBlockBuilder {
DataVisualizationBlockBuilder::default()
}
pub fn into_builder(self) -> DataVisualizationBlockBuilder {
DataVisualizationBlockBuilder {
title: Some(self.title),
chart: Some(self.chart),
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn title(&self) -> &str {
&self.title
}
pub fn chart(&self) -> &Chart {
&self.chart
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "data_visualization")?;
map.serialize_entry("title", &self.title)?;
map.serialize_entry("chart", &self.chart)?;
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl DataVisualizationBlockBuilder {
pub fn title(mut self, value: impl Into<String>) -> Self {
self.title = Some(value.into());
self
}
pub fn chart(mut self, value: impl Into<Chart>) -> Self {
self.chart = Some(value.into());
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<DataVisualizationBlock, ValidationError> {
let title = wire::required(self.title, "DataVisualizationBlock.title")?;
let chart = wire::required(self.chart, "DataVisualizationBlock.chart")?;
let block_id = self.block_id;
wire::extensions(
&self.extensions,
&["title", "chart", "block_id"],
"DataVisualizationBlock",
)?;
let value = DataVisualizationBlock {
title,
chart,
block_id,
extensions: self.extensions,
};
{
let v = &value.title;
crate::rules::length(
v.chars().count(),
None,
Some(50),
"DataVisualizationBlock.title",
)?;
}
if let Some(v) = &value.block_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"DataVisualizationBlock.block_id",
)?;
}
Ok(value)
}
}
impl Serialize for DataVisualizationBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for DataVisualizationBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "data_visualization", path)?;
let title = wire::field::<String>(&mut map, "title", path)?;
let chart = wire::field::<Chart>(&mut map, "chart", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
DataVisualizationBlockBuilder {
title,
chart,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for DataVisualizationBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "DataVisualizationBlock")
}
}
impl<'de> Deserialize<'de> for DataVisualizationBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct DividerBlock {
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct DividerBlockBuilder {
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for DividerBlockBuilder {
fn default() -> Self {
Self {
block_id: None,
extensions: Map::new(),
}
}
}
impl DividerBlock {
pub fn builder() -> DividerBlockBuilder {
DividerBlockBuilder::default()
}
pub fn into_builder(self) -> DividerBlockBuilder {
DividerBlockBuilder {
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "divider")?;
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl DividerBlockBuilder {
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<DividerBlock, ValidationError> {
let block_id = self.block_id;
wire::extensions(&self.extensions, &["block_id"], "DividerBlock")?;
let value = DividerBlock {
block_id,
extensions: self.extensions,
};
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "DividerBlock.block_id")?;
}
Ok(value)
}
}
impl Serialize for DividerBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for DividerBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "divider", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
DividerBlockBuilder {
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for DividerBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "DividerBlock")
}
}
impl<'de> Deserialize<'de> for DividerBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct FileBlock {
external_id: String,
source: String,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct FileBlockBuilder {
external_id: Option<String>,
source: Option<String>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for FileBlockBuilder {
fn default() -> Self {
Self {
external_id: None,
source: Some("remote".into()),
block_id: None,
extensions: Map::new(),
}
}
}
impl FileBlock {
pub fn builder() -> FileBlockBuilder {
FileBlockBuilder::default()
}
pub fn into_builder(self) -> FileBlockBuilder {
FileBlockBuilder {
external_id: Some(self.external_id),
source: Some(self.source),
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn external_id(&self) -> &str {
&self.external_id
}
pub fn source(&self) -> &str {
&self.source
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "file")?;
map.serialize_entry("external_id", &self.external_id)?;
map.serialize_entry("source", &self.source)?;
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl FileBlockBuilder {
pub fn external_id(mut self, value: impl Into<String>) -> Self {
self.external_id = Some(value.into());
self
}
pub fn source(mut self, value: impl Into<String>) -> Self {
self.source = Some(value.into());
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<FileBlock, ValidationError> {
let external_id = wire::required(self.external_id, "FileBlock.external_id")?;
let source = wire::required(self.source, "FileBlock.source")?;
let block_id = self.block_id;
wire::extensions(
&self.extensions,
&["external_id", "source", "block_id"],
"FileBlock",
)?;
let value = FileBlock {
external_id,
source,
block_id,
extensions: self.extensions,
};
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "FileBlock.block_id")?;
}
Ok(value)
}
}
impl Serialize for FileBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for FileBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "file", path)?;
let external_id = wire::field::<String>(&mut map, "external_id", path)?;
if !map.contains_key("source") {
map.insert("source".into(), serde_json::json!("remote"));
}
let source = wire::field::<String>(&mut map, "source", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
FileBlockBuilder {
external_id,
source,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for FileBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "FileBlock")
}
}
impl<'de> Deserialize<'de> for FileBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct HeaderBlock {
text: PlainText,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct HeaderBlockBuilder {
text: Option<PlainTextInput>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for HeaderBlockBuilder {
fn default() -> Self {
Self {
text: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl HeaderBlock {
pub fn builder() -> HeaderBlockBuilder {
HeaderBlockBuilder::default()
}
pub fn into_builder(self) -> HeaderBlockBuilder {
HeaderBlockBuilder {
text: Some(self.text.into()),
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn text(&self) -> &PlainText {
&self.text
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "header")?;
map.serialize_entry("text", &self.text)?;
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl HeaderBlockBuilder {
pub fn text(mut self, value: impl Into<PlainTextInput>) -> Self {
self.text = Some(value.into());
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<HeaderBlock, ValidationError> {
let text = wire::required(
self.text
.map(|v| v.resolve().map_err(|e| e.at("HeaderBlock.text")))
.transpose()?,
"HeaderBlock.text",
)?;
let block_id = self.block_id;
wire::extensions(&self.extensions, &["text", "block_id"], "HeaderBlock")?;
let value = HeaderBlock {
text,
block_id,
extensions: self.extensions,
};
{
let v = &value.text;
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"HeaderBlock.text",
)?;
}
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "HeaderBlock.block_id")?;
}
Ok(value)
}
}
impl Serialize for HeaderBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for HeaderBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "header", path)?;
crate::rules::coerce_text(map.get_mut("text"), "plain_text");
let text = wire::field::<PlainText>(&mut map, "text", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
HeaderBlockBuilder {
text: text.map(Into::into),
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for HeaderBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "HeaderBlock")
}
}
impl<'de> Deserialize<'de> for HeaderBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ImageBlock {
image_url: Option<String>,
slack_file: Option<SlackFile>,
alt_text: String,
title: Option<PlainText>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ImageBlockBuilder {
image_url: Option<String>,
slack_file: Option<SlackFile>,
alt_text: Option<String>,
title: Option<PlainTextInput>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for ImageBlockBuilder {
fn default() -> Self {
Self {
image_url: None,
slack_file: None,
alt_text: None,
title: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl ImageBlock {
pub fn builder() -> ImageBlockBuilder {
ImageBlockBuilder::default()
}
pub fn into_builder(self) -> ImageBlockBuilder {
ImageBlockBuilder {
image_url: self.image_url,
slack_file: self.slack_file,
alt_text: Some(self.alt_text),
title: self.title.map(Into::into),
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn image_url(&self) -> Option<&str> {
self.image_url.as_deref()
}
pub fn slack_file(&self) -> Option<&SlackFile> {
self.slack_file.as_ref()
}
pub fn alt_text(&self) -> &str {
&self.alt_text
}
pub fn title(&self) -> Option<&PlainText> {
self.title.as_ref()
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "image")?;
if let Some(value) = &self.image_url {
map.serialize_entry("image_url", value)?;
}
if let Some(value) = &self.slack_file {
map.serialize_entry("slack_file", value)?;
}
map.serialize_entry("alt_text", &self.alt_text)?;
if let Some(value) = &self.title {
map.serialize_entry("title", value)?;
}
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ImageBlockBuilder {
pub fn image_url(mut self, value: impl Into<String>) -> Self {
self.image_url = Some(value.into());
self
}
pub fn clear_image_url(mut self) -> Self {
self.image_url = None;
self
}
pub fn slack_file(mut self, value: impl Into<SlackFile>) -> Self {
self.slack_file = Some(value.into());
self
}
pub fn clear_slack_file(mut self) -> Self {
self.slack_file = None;
self
}
pub fn alt_text(mut self, value: impl Into<String>) -> Self {
self.alt_text = Some(value.into());
self
}
pub fn title(mut self, value: impl Into<PlainTextInput>) -> Self {
self.title = Some(value.into());
self
}
pub fn clear_title(mut self) -> Self {
self.title = None;
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ImageBlock, ValidationError> {
let image_url = self.image_url;
let slack_file = self.slack_file;
let alt_text = wire::required(self.alt_text, "ImageBlock.alt_text")?;
let title = self
.title
.map(|v| v.resolve().map_err(|e| e.at("ImageBlock.title")))
.transpose()?;
let block_id = self.block_id;
wire::extensions(
&self.extensions,
&["image_url", "slack_file", "alt_text", "title", "block_id"],
"ImageBlock",
)?;
let value = ImageBlock {
image_url,
slack_file,
alt_text,
title,
block_id,
extensions: self.extensions,
};
if let Some(v) = &value.image_url {
crate::rules::length(v.chars().count(), None, Some(3000), "ImageBlock.image_url")?;
}
{
let v = &value.alt_text;
crate::rules::length(v.chars().count(), None, Some(2000), "ImageBlock.alt_text")?;
}
if let Some(v) = &value.title {
crate::rules::length(
v.text().chars().count(),
None,
Some(2000),
"ImageBlock.title",
)?;
}
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "ImageBlock.block_id")?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "ImageBlock", e.to_string())
})?;
crate::rules::validate("ImageBlock", &wire, "ImageBlock")?;
Ok(value)
}
}
impl Serialize for ImageBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ImageBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "image", path)?;
let image_url = wire::field::<String>(&mut map, "image_url", path)?;
let slack_file = wire::field::<SlackFile>(&mut map, "slack_file", path)?;
let alt_text = wire::field::<String>(&mut map, "alt_text", path)?;
crate::rules::coerce_text(map.get_mut("title"), "plain_text");
let title = wire::field::<PlainText>(&mut map, "title", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
ImageBlockBuilder {
image_url,
slack_file,
alt_text,
title: title.map(Into::into),
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ImageBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ImageBlock")
}
}
impl<'de> Deserialize<'de> for ImageBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct InputBlock {
label: PlainText,
element: InputElement,
dispatch_action: Option<bool>,
block_id: Option<String>,
hint: Option<PlainText>,
optional: Option<bool>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct InputBlockBuilder {
label: Option<PlainTextInput>,
element: Option<InputElement>,
dispatch_action: Option<bool>,
block_id: Option<String>,
hint: Option<PlainTextInput>,
optional: Option<bool>,
extensions: Map<String, Value>,
}
impl Default for InputBlockBuilder {
fn default() -> Self {
Self {
label: None,
element: None,
dispatch_action: None,
block_id: None,
hint: None,
optional: None,
extensions: Map::new(),
}
}
}
impl InputBlock {
pub fn builder() -> InputBlockBuilder {
InputBlockBuilder::default()
}
pub fn into_builder(self) -> InputBlockBuilder {
InputBlockBuilder {
label: Some(self.label.into()),
element: Some(self.element),
dispatch_action: self.dispatch_action,
block_id: self.block_id,
hint: self.hint.map(Into::into),
optional: self.optional,
extensions: self.extensions,
}
}
pub fn label(&self) -> &PlainText {
&self.label
}
pub fn element(&self) -> &InputElement {
&self.element
}
pub fn dispatch_action(&self) -> Option<bool> {
self.dispatch_action
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn hint(&self) -> Option<&PlainText> {
self.hint.as_ref()
}
pub fn optional(&self) -> Option<bool> {
self.optional
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "input")?;
map.serialize_entry("label", &self.label)?;
map.serialize_entry("element", &self.element)?;
if let Some(value) = &self.dispatch_action {
map.serialize_entry("dispatch_action", value)?;
}
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
if let Some(value) = &self.hint {
map.serialize_entry("hint", value)?;
}
if let Some(value) = &self.optional {
map.serialize_entry("optional", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl InputBlockBuilder {
pub fn label(mut self, value: impl Into<PlainTextInput>) -> Self {
self.label = Some(value.into());
self
}
pub fn element(mut self, value: impl Into<InputElement>) -> Self {
self.element = Some(value.into());
self
}
pub fn dispatch_action(mut self, value: bool) -> Self {
self.dispatch_action = Some(value);
self
}
pub fn clear_dispatch_action(mut self) -> Self {
self.dispatch_action = None;
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn hint(mut self, value: impl Into<PlainTextInput>) -> Self {
self.hint = Some(value.into());
self
}
pub fn clear_hint(mut self) -> Self {
self.hint = None;
self
}
pub fn optional(mut self, value: bool) -> Self {
self.optional = Some(value);
self
}
pub fn clear_optional(mut self) -> Self {
self.optional = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<InputBlock, ValidationError> {
let label = wire::required(
self.label
.map(|v| v.resolve().map_err(|e| e.at("InputBlock.label")))
.transpose()?,
"InputBlock.label",
)?;
let element = wire::required(self.element, "InputBlock.element")?;
let dispatch_action = self.dispatch_action;
let block_id = self.block_id;
let hint = self
.hint
.map(|v| v.resolve().map_err(|e| e.at("InputBlock.hint")))
.transpose()?;
let optional = self.optional;
wire::extensions(
&self.extensions,
&[
"label",
"element",
"dispatch_action",
"block_id",
"hint",
"optional",
],
"InputBlock",
)?;
let value = InputBlock {
label,
element,
dispatch_action,
block_id,
hint,
optional,
extensions: self.extensions,
};
{
let v = &value.label;
crate::rules::length(
v.text().chars().count(),
None,
Some(2000),
"InputBlock.label",
)?;
}
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "InputBlock.block_id")?;
}
if let Some(v) = &value.hint {
crate::rules::length(
v.text().chars().count(),
None,
Some(2000),
"InputBlock.hint",
)?;
}
Ok(value)
}
}
impl Serialize for InputBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for InputBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "input", path)?;
crate::rules::coerce_text(map.get_mut("label"), "plain_text");
let label = wire::field::<PlainText>(&mut map, "label", path)?;
let element = wire::field::<InputElement>(&mut map, "element", path)?;
let dispatch_action = wire::field::<bool>(&mut map, "dispatch_action", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
crate::rules::coerce_text(map.get_mut("hint"), "plain_text");
let hint = wire::field::<PlainText>(&mut map, "hint", path)?;
let optional = wire::field::<bool>(&mut map, "optional", path)?;
InputBlockBuilder {
label: label.map(Into::into),
element,
dispatch_action,
block_id,
hint: hint.map(Into::into),
optional,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for InputBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "InputBlock")
}
}
impl<'de> Deserialize<'de> for InputBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct MarkdownBlock {
text: String,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct MarkdownBlockBuilder {
text: Option<String>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for MarkdownBlockBuilder {
fn default() -> Self {
Self {
text: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl MarkdownBlock {
pub fn builder() -> MarkdownBlockBuilder {
MarkdownBlockBuilder::default()
}
pub fn into_builder(self) -> MarkdownBlockBuilder {
MarkdownBlockBuilder {
text: Some(self.text),
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn text(&self) -> &str {
&self.text
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "markdown")?;
map.serialize_entry("text", &self.text)?;
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl MarkdownBlockBuilder {
pub fn text(mut self, value: impl Into<String>) -> Self {
self.text = Some(value.into());
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<MarkdownBlock, ValidationError> {
let text = wire::required(self.text, "MarkdownBlock.text")?;
let block_id = self.block_id;
wire::extensions(&self.extensions, &["text", "block_id"], "MarkdownBlock")?;
let value = MarkdownBlock {
text,
block_id,
extensions: self.extensions,
};
{
let v = &value.text;
crate::rules::length(v.chars().count(), None, Some(12000), "MarkdownBlock.text")?;
}
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "MarkdownBlock.block_id")?;
}
Ok(value)
}
}
impl Serialize for MarkdownBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for MarkdownBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "markdown", path)?;
let text = wire::field::<String>(&mut map, "text", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
MarkdownBlockBuilder {
text,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for MarkdownBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "MarkdownBlock")
}
}
impl<'de> Deserialize<'de> for MarkdownBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct PlanBlock {
title: String,
tasks: Vec<TaskCardBlock>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct PlanBlockBuilder {
title: Option<String>,
tasks: Option<Vec<TaskCardBlock>>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for PlanBlockBuilder {
fn default() -> Self {
Self {
title: None,
tasks: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl PlanBlock {
pub fn builder() -> PlanBlockBuilder {
PlanBlockBuilder::default()
}
pub fn into_builder(self) -> PlanBlockBuilder {
PlanBlockBuilder {
title: Some(self.title),
tasks: Some(self.tasks),
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn title(&self) -> &str {
&self.title
}
pub fn tasks(&self) -> &[TaskCardBlock] {
&self.tasks
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "plan")?;
map.serialize_entry("title", &self.title)?;
map.serialize_entry("tasks", &crate::rules::PlanTasks(&self.tasks))?;
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl PlanBlockBuilder {
pub fn title(mut self, value: impl Into<String>) -> Self {
self.title = Some(value.into());
self
}
pub fn tasks<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<TaskCardBlock>,
{
self.tasks = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn task(mut self, value: impl Into<TaskCardBlock>) -> Self {
self.tasks.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<PlanBlock, ValidationError> {
let title = wire::required(self.title, "PlanBlock.title")?;
let tasks = wire::required(self.tasks, "PlanBlock.tasks")?;
let block_id = self.block_id;
wire::extensions(
&self.extensions,
&["title", "tasks", "block_id"],
"PlanBlock",
)?;
let value = PlanBlock {
title,
tasks,
block_id,
extensions: self.extensions,
};
{
let v = &value.tasks;
crate::rules::length(v.len(), None, Some(50), "PlanBlock.tasks")?;
}
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "PlanBlock.block_id")?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "PlanBlock", e.to_string())
})?;
crate::rules::validate("PlanBlock", &wire, "PlanBlock")?;
Ok(value)
}
}
impl Serialize for PlanBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for PlanBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "plan", path)?;
let title = wire::field::<String>(&mut map, "title", path)?;
crate::rules::restore_tasks(map.get_mut("tasks"));
let tasks = wire::field::<Vec<TaskCardBlock>>(&mut map, "tasks", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
PlanBlockBuilder {
title,
tasks,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for PlanBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "PlanBlock")
}
}
impl<'de> Deserialize<'de> for PlanBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RichTextBlock {
elements: Vec<RichTextBlockElement>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RichTextBlockBuilder {
elements: Option<Vec<RichTextBlockElement>>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for RichTextBlockBuilder {
fn default() -> Self {
Self {
elements: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl RichTextBlock {
pub fn builder() -> RichTextBlockBuilder {
RichTextBlockBuilder::default()
}
pub fn into_builder(self) -> RichTextBlockBuilder {
RichTextBlockBuilder {
elements: Some(self.elements),
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn elements(&self) -> &[RichTextBlockElement] {
&self.elements
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "rich_text")?;
map.serialize_entry("elements", &self.elements)?;
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RichTextBlockBuilder {
pub fn elements<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<RichTextBlockElement>,
{
self.elements = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn element(mut self, value: impl Into<RichTextBlockElement>) -> Self {
self.elements
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RichTextBlock, ValidationError> {
let elements = wire::required(self.elements, "RichTextBlock.elements")?;
let block_id = self.block_id;
wire::extensions(&self.extensions, &["elements", "block_id"], "RichTextBlock")?;
let value = RichTextBlock {
elements,
block_id,
extensions: self.extensions,
};
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "RichTextBlock.block_id")?;
}
Ok(value)
}
}
impl Serialize for RichTextBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RichTextBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "rich_text", path)?;
let elements = wire::field::<Vec<RichTextBlockElement>>(&mut map, "elements", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
RichTextBlockBuilder {
elements,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RichTextBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextBlock")
}
}
impl<'de> Deserialize<'de> for RichTextBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct SectionBlock {
text: Option<Text>,
fields: Option<Vec<Text>>,
accessory: Option<Element>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct SectionBlockBuilder {
text: Option<TextInput>,
fields: Option<Vec<TextInput>>,
accessory: Option<Element>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for SectionBlockBuilder {
fn default() -> Self {
Self {
text: None,
fields: None,
accessory: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl SectionBlock {
pub fn builder() -> SectionBlockBuilder {
SectionBlockBuilder::default()
}
pub fn into_builder(self) -> SectionBlockBuilder {
SectionBlockBuilder {
text: self.text.map(Into::into),
fields: self.fields.map(|v| v.into_iter().map(Into::into).collect()),
accessory: self.accessory,
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn text(&self) -> Option<&Text> {
self.text.as_ref()
}
pub fn fields(&self) -> Option<&[Text]> {
self.fields.as_deref()
}
pub fn accessory(&self) -> Option<&Element> {
self.accessory.as_ref()
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "section")?;
if let Some(value) = &self.text {
map.serialize_entry("text", value)?;
}
if let Some(value) = &self.fields {
map.serialize_entry("fields", value)?;
}
if let Some(value) = &self.accessory {
map.serialize_entry("accessory", value)?;
}
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl SectionBlockBuilder {
pub fn text(mut self, value: impl Into<TextInput>) -> Self {
self.text = Some(value.into());
self
}
pub fn clear_text(mut self) -> Self {
self.text = None;
self
}
pub fn fields<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<TextInput>,
{
self.fields = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn field(mut self, value: impl Into<TextInput>) -> Self {
self.fields.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn clear_fields(mut self) -> Self {
self.fields = None;
self
}
pub fn accessory(mut self, value: impl Into<Element>) -> Self {
self.accessory = Some(value.into());
self
}
pub fn clear_accessory(mut self) -> Self {
self.accessory = None;
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<SectionBlock, ValidationError> {
let text = self
.text
.map(|v| v.resolve(false).map_err(|e| e.at("SectionBlock.text")))
.transpose()?;
let fields = self
.fields
.map(|vs| {
vs.into_iter()
.enumerate()
.map(|(i, v)| {
v.resolve(false)
.map_err(|e| e.at(&format!("SectionBlock.fields[{i}]")))
})
.collect::<Result<Vec<_>, _>>()
})
.transpose()?;
let accessory = self.accessory;
let block_id = self.block_id;
wire::extensions(
&self.extensions,
&["text", "fields", "accessory", "block_id"],
"SectionBlock",
)?;
let value = SectionBlock {
text,
fields,
accessory,
block_id,
extensions: self.extensions,
};
if let Some(v) = &value.text {
crate::rules::length(
crate::rules::text_len(v),
None,
Some(3000),
"SectionBlock.text",
)?;
}
if let Some(v) = &value.fields {
crate::rules::length(v.len(), None, Some(10), "SectionBlock.fields")?;
for (i, item) in v.iter().enumerate() {
crate::rules::length(
crate::rules::text_len(item),
None,
Some(2000),
&format!("SectionBlock.fields[{i}].text"),
)?;
}
}
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "SectionBlock.block_id")?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "SectionBlock", e.to_string())
})?;
crate::rules::validate("SectionBlock", &wire, "SectionBlock")?;
Ok(value)
}
}
impl Serialize for SectionBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for SectionBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "section", path)?;
crate::rules::coerce_text(map.get_mut("text"), "mrkdwn");
let text = wire::field::<Text>(&mut map, "text", path)?;
if let Some(Value::Array(vs)) = map.get_mut("fields") {
for v in vs {
crate::rules::coerce_text(Some(v), "mrkdwn");
}
}
let fields = wire::field::<Vec<Text>>(&mut map, "fields", path)?;
let accessory = wire::field::<Element>(&mut map, "accessory", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
SectionBlockBuilder {
text: text.map(Into::into),
fields: fields.map(|vs| vs.into_iter().map(Into::into).collect()),
accessory,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for SectionBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "SectionBlock")
}
}
impl<'de> Deserialize<'de> for SectionBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct TableBlock {
rows: Vec<Vec<TableCell>>,
column_settings: Option<Vec<ColumnSettings>>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct TableBlockBuilder {
rows: Option<Vec<Vec<TableCell>>>,
column_settings: Option<Vec<ColumnSettings>>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for TableBlockBuilder {
fn default() -> Self {
Self {
rows: None,
column_settings: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl TableBlock {
pub fn builder() -> TableBlockBuilder {
TableBlockBuilder::default()
}
pub fn into_builder(self) -> TableBlockBuilder {
TableBlockBuilder {
rows: Some(self.rows),
column_settings: self.column_settings,
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn rows(&self) -> &[Vec<TableCell>] {
&self.rows
}
pub fn column_settings(&self) -> Option<&[ColumnSettings]> {
self.column_settings.as_deref()
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "table")?;
map.serialize_entry("rows", &self.rows)?;
if let Some(value) = &self.column_settings {
map.serialize_entry("column_settings", value)?;
}
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl TableBlockBuilder {
pub fn rows<I, R, T>(mut self, rows: I) -> Self
where
I: IntoIterator<Item = R>,
R: IntoIterator<Item = T>,
T: Into<TableCell>,
{
self.rows = Some(
rows.into_iter()
.map(|r| r.into_iter().map(Into::into).collect())
.collect(),
);
self
}
pub fn row<I, T>(mut self, row: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<TableCell>,
{
self.rows
.get_or_insert_with(Vec::new)
.push(row.into_iter().map(Into::into).collect());
self
}
pub fn column_settings<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<ColumnSettings>,
{
self.column_settings = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn column_setting(mut self, value: impl Into<ColumnSettings>) -> Self {
self.column_settings
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_column_settings(mut self) -> Self {
self.column_settings = None;
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<TableBlock, ValidationError> {
let rows = wire::required(self.rows, "TableBlock.rows")?;
let column_settings = self.column_settings;
let block_id = self.block_id;
wire::extensions(
&self.extensions,
&["rows", "column_settings", "block_id"],
"TableBlock",
)?;
let value = TableBlock {
rows,
column_settings,
block_id,
extensions: self.extensions,
};
{
let v = &value.rows;
crate::rules::length(v.len(), None, Some(100), "TableBlock.rows")?;
}
if let Some(v) = &value.column_settings {
crate::rules::length(v.len(), None, Some(20), "TableBlock.column_settings")?;
}
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "TableBlock.block_id")?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "TableBlock", e.to_string())
})?;
crate::rules::validate("TableBlock", &wire, "TableBlock")?;
Ok(value)
}
}
impl Serialize for TableBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for TableBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "table", path)?;
let rows = wire::field::<Vec<Vec<TableCell>>>(&mut map, "rows", path)?;
let column_settings =
wire::field::<Vec<ColumnSettings>>(&mut map, "column_settings", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
TableBlockBuilder {
rows,
column_settings,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for TableBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "TableBlock")
}
}
impl<'de> Deserialize<'de> for TableBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct TaskCardBlock {
task_id: String,
title: String,
details: Option<RichTextBlock>,
output: Option<RichTextBlock>,
sources: Option<Vec<UrlSource>>,
status: TaskStatus,
block_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct TaskCardBlockBuilder {
task_id: Option<String>,
title: Option<String>,
details: Option<RichTextBlock>,
output: Option<RichTextBlock>,
sources: Option<Vec<UrlSource>>,
status: Option<TaskStatus>,
block_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for TaskCardBlockBuilder {
fn default() -> Self {
Self {
task_id: None,
title: None,
details: None,
output: None,
sources: None,
status: None,
block_id: None,
extensions: Map::new(),
}
}
}
impl TaskCardBlock {
pub fn builder() -> TaskCardBlockBuilder {
TaskCardBlockBuilder::default()
}
pub fn into_builder(self) -> TaskCardBlockBuilder {
TaskCardBlockBuilder {
task_id: Some(self.task_id),
title: Some(self.title),
details: self.details,
output: self.output,
sources: self.sources,
status: Some(self.status),
block_id: self.block_id,
extensions: self.extensions,
}
}
pub fn task_id(&self) -> &str {
&self.task_id
}
pub fn title(&self) -> &str {
&self.title
}
pub fn details(&self) -> Option<&RichTextBlock> {
self.details.as_ref()
}
pub fn output(&self) -> Option<&RichTextBlock> {
self.output.as_ref()
}
pub fn sources(&self) -> Option<&[UrlSource]> {
self.sources.as_deref()
}
pub fn status(&self) -> TaskStatus {
self.status
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
pub(crate) fn serialize_value<S: Serializer>(
&self,
serializer: S,
tagged: bool,
) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
if tagged {
map.serialize_entry("type", "task_card")?;
}
map.serialize_entry("task_id", &self.task_id)?;
map.serialize_entry("title", &self.title)?;
if let Some(value) = &self.details {
map.serialize_entry("details", value)?;
}
if let Some(value) = &self.output {
map.serialize_entry("output", value)?;
}
if let Some(value) = &self.sources {
map.serialize_entry("sources", value)?;
}
map.serialize_entry("status", &self.status)?;
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl TaskCardBlockBuilder {
pub fn task_id(mut self, value: impl Into<String>) -> Self {
self.task_id = Some(value.into());
self
}
pub fn title(mut self, value: impl Into<String>) -> Self {
self.title = Some(value.into());
self
}
pub fn details(mut self, value: impl Into<RichTextBlock>) -> Self {
self.details = Some(value.into());
self
}
pub fn clear_details(mut self) -> Self {
self.details = None;
self
}
pub fn output(mut self, value: impl Into<RichTextBlock>) -> Self {
self.output = Some(value.into());
self
}
pub fn clear_output(mut self) -> Self {
self.output = None;
self
}
pub fn sources<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<UrlSource>,
{
self.sources = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn source(mut self, value: impl Into<UrlSource>) -> Self {
self.sources.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn clear_sources(mut self) -> Self {
self.sources = None;
self
}
pub fn status(mut self, value: TaskStatus) -> Self {
self.status = Some(value);
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<TaskCardBlock, ValidationError> {
let task_id = wire::required(self.task_id, "TaskCardBlock.task_id")?;
let title = wire::required(self.title, "TaskCardBlock.title")?;
let details = self.details;
let output = self.output;
let sources = self.sources;
let status = wire::required(self.status, "TaskCardBlock.status")?;
let block_id = self.block_id;
wire::extensions(
&self.extensions,
&[
"task_id", "title", "details", "output", "sources", "status", "block_id",
],
"TaskCardBlock",
)?;
let value = TaskCardBlock {
task_id,
title,
details,
output,
sources,
status,
block_id,
extensions: self.extensions,
};
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "TaskCardBlock.block_id")?;
}
Ok(value)
}
}
impl Serialize for TaskCardBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s, true)
}
}
impl FromWire for TaskCardBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "task_card", path)?;
let task_id = wire::field::<String>(&mut map, "task_id", path)?;
let title = wire::field::<String>(&mut map, "title", path)?;
let details = wire::field::<RichTextBlock>(&mut map, "details", path)?;
let output = wire::field::<RichTextBlock>(&mut map, "output", path)?;
let sources = wire::field::<Vec<UrlSource>>(&mut map, "sources", path)?;
let status = wire::field::<TaskStatus>(&mut map, "status", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
TaskCardBlockBuilder {
task_id,
title,
details,
output,
sources,
status,
block_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for TaskCardBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "TaskCardBlock")
}
}
impl<'de> Deserialize<'de> for TaskCardBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct VideoBlock {
alt_text: String,
thumbnail_url: String,
title: PlainText,
video_url: String,
block_id: Option<String>,
author_name: Option<String>,
description: Option<PlainText>,
provider_icon_url: Option<String>,
provider_name: Option<String>,
title_url: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct VideoBlockBuilder {
alt_text: Option<String>,
thumbnail_url: Option<String>,
title: Option<PlainTextInput>,
video_url: Option<String>,
block_id: Option<String>,
author_name: Option<String>,
description: Option<PlainTextInput>,
provider_icon_url: Option<String>,
provider_name: Option<String>,
title_url: Option<String>,
extensions: Map<String, Value>,
}
impl Default for VideoBlockBuilder {
fn default() -> Self {
Self {
alt_text: None,
thumbnail_url: None,
title: None,
video_url: None,
block_id: None,
author_name: None,
description: None,
provider_icon_url: None,
provider_name: None,
title_url: None,
extensions: Map::new(),
}
}
}
impl VideoBlock {
pub fn builder() -> VideoBlockBuilder {
VideoBlockBuilder::default()
}
pub fn into_builder(self) -> VideoBlockBuilder {
VideoBlockBuilder {
alt_text: Some(self.alt_text),
thumbnail_url: Some(self.thumbnail_url),
title: Some(self.title.into()),
video_url: Some(self.video_url),
block_id: self.block_id,
author_name: self.author_name,
description: self.description.map(Into::into),
provider_icon_url: self.provider_icon_url,
provider_name: self.provider_name,
title_url: self.title_url,
extensions: self.extensions,
}
}
pub fn alt_text(&self) -> &str {
&self.alt_text
}
pub fn thumbnail_url(&self) -> &str {
&self.thumbnail_url
}
pub fn title(&self) -> &PlainText {
&self.title
}
pub fn video_url(&self) -> &str {
&self.video_url
}
pub fn block_id(&self) -> Option<&str> {
self.block_id.as_deref()
}
pub fn author_name(&self) -> Option<&str> {
self.author_name.as_deref()
}
pub fn description(&self) -> Option<&PlainText> {
self.description.as_ref()
}
pub fn provider_icon_url(&self) -> Option<&str> {
self.provider_icon_url.as_deref()
}
pub fn provider_name(&self) -> Option<&str> {
self.provider_name.as_deref()
}
pub fn title_url(&self) -> Option<&str> {
self.title_url.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "video")?;
map.serialize_entry("alt_text", &self.alt_text)?;
map.serialize_entry("thumbnail_url", &self.thumbnail_url)?;
map.serialize_entry("title", &self.title)?;
map.serialize_entry("video_url", &self.video_url)?;
if let Some(value) = &self.block_id {
map.serialize_entry("block_id", value)?;
}
if let Some(value) = &self.author_name {
map.serialize_entry("author_name", value)?;
}
if let Some(value) = &self.description {
map.serialize_entry("description", value)?;
}
if let Some(value) = &self.provider_icon_url {
map.serialize_entry("provider_icon_url", value)?;
}
if let Some(value) = &self.provider_name {
map.serialize_entry("provider_name", value)?;
}
if let Some(value) = &self.title_url {
map.serialize_entry("title_url", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl VideoBlockBuilder {
pub fn alt_text(mut self, value: impl Into<String>) -> Self {
self.alt_text = Some(value.into());
self
}
pub fn thumbnail_url(mut self, value: impl Into<String>) -> Self {
self.thumbnail_url = Some(value.into());
self
}
pub fn title(mut self, value: impl Into<PlainTextInput>) -> Self {
self.title = Some(value.into());
self
}
pub fn video_url(mut self, value: impl Into<String>) -> Self {
self.video_url = Some(value.into());
self
}
pub fn block_id(mut self, value: impl Into<String>) -> Self {
self.block_id = Some(value.into());
self
}
pub fn clear_block_id(mut self) -> Self {
self.block_id = None;
self
}
pub fn author_name(mut self, value: impl Into<String>) -> Self {
self.author_name = Some(value.into());
self
}
pub fn clear_author_name(mut self) -> Self {
self.author_name = None;
self
}
pub fn description(mut self, value: impl Into<PlainTextInput>) -> Self {
self.description = Some(value.into());
self
}
pub fn clear_description(mut self) -> Self {
self.description = None;
self
}
pub fn provider_icon_url(mut self, value: impl Into<String>) -> Self {
self.provider_icon_url = Some(value.into());
self
}
pub fn clear_provider_icon_url(mut self) -> Self {
self.provider_icon_url = None;
self
}
pub fn provider_name(mut self, value: impl Into<String>) -> Self {
self.provider_name = Some(value.into());
self
}
pub fn clear_provider_name(mut self) -> Self {
self.provider_name = None;
self
}
pub fn title_url(mut self, value: impl Into<String>) -> Self {
self.title_url = Some(value.into());
self
}
pub fn clear_title_url(mut self) -> Self {
self.title_url = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<VideoBlock, ValidationError> {
let alt_text = wire::required(self.alt_text, "VideoBlock.alt_text")?;
let thumbnail_url = wire::required(self.thumbnail_url, "VideoBlock.thumbnail_url")?;
let title = wire::required(
self.title
.map(|v| v.resolve().map_err(|e| e.at("VideoBlock.title")))
.transpose()?,
"VideoBlock.title",
)?;
let video_url = wire::required(self.video_url, "VideoBlock.video_url")?;
let block_id = self.block_id;
let author_name = self.author_name;
let description = self
.description
.map(|v| v.resolve().map_err(|e| e.at("VideoBlock.description")))
.transpose()?;
let provider_icon_url = self.provider_icon_url;
let provider_name = self.provider_name;
let title_url = self.title_url;
wire::extensions(
&self.extensions,
&[
"alt_text",
"thumbnail_url",
"title",
"video_url",
"block_id",
"author_name",
"description",
"provider_icon_url",
"provider_name",
"title_url",
],
"VideoBlock",
)?;
let value = VideoBlock {
alt_text,
thumbnail_url,
title,
video_url,
block_id,
author_name,
description,
provider_icon_url,
provider_name,
title_url,
extensions: self.extensions,
};
{
let v = &value.alt_text;
crate::rules::length(v.chars().count(), None, Some(2000), "VideoBlock.alt_text")?;
}
{
let v = &value.thumbnail_url;
crate::rules::length(
v.chars().count(),
None,
Some(3000),
"VideoBlock.thumbnail_url",
)?;
}
{
let v = &value.title;
crate::rules::length(
v.text().chars().count(),
None,
Some(200),
"VideoBlock.title",
)?;
}
{
let v = &value.video_url;
crate::rules::length(v.chars().count(), None, Some(3000), "VideoBlock.video_url")?;
}
if let Some(v) = &value.block_id {
crate::rules::length(v.chars().count(), None, Some(255), "VideoBlock.block_id")?;
}
if let Some(v) = &value.author_name {
crate::rules::length(v.chars().count(), None, Some(50), "VideoBlock.author_name")?;
}
if let Some(v) = &value.description {
crate::rules::length(
v.text().chars().count(),
None,
Some(200),
"VideoBlock.description",
)?;
}
if let Some(v) = &value.provider_icon_url {
crate::rules::length(
v.chars().count(),
None,
Some(2000),
"VideoBlock.provider_icon_url",
)?;
}
if let Some(v) = &value.provider_name {
crate::rules::length(
v.chars().count(),
None,
Some(50),
"VideoBlock.provider_name",
)?;
}
if let Some(v) = &value.title_url {
crate::rules::length(v.chars().count(), None, Some(2000), "VideoBlock.title_url")?;
}
Ok(value)
}
}
impl Serialize for VideoBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for VideoBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "video", path)?;
let alt_text = wire::field::<String>(&mut map, "alt_text", path)?;
let thumbnail_url = wire::field::<String>(&mut map, "thumbnail_url", path)?;
crate::rules::coerce_text(map.get_mut("title"), "plain_text");
let title = wire::field::<PlainText>(&mut map, "title", path)?;
let video_url = wire::field::<String>(&mut map, "video_url", path)?;
let block_id = wire::field::<String>(&mut map, "block_id", path)?;
let author_name = wire::field::<String>(&mut map, "author_name", path)?;
crate::rules::coerce_text(map.get_mut("description"), "plain_text");
let description = wire::field::<PlainText>(&mut map, "description", path)?;
let provider_icon_url = wire::field::<String>(&mut map, "provider_icon_url", path)?;
let provider_name = wire::field::<String>(&mut map, "provider_name", path)?;
let title_url = wire::field::<String>(&mut map, "title_url", path)?;
VideoBlockBuilder {
alt_text,
thumbnail_url,
title: title.map(Into::into),
video_url,
block_id,
author_name,
description: description.map(Into::into),
provider_icon_url,
provider_name,
title_url,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for VideoBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "VideoBlock")
}
}
impl<'de> Deserialize<'de> for VideoBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ButtonElement {
text: PlainText,
action_id: Option<String>,
url: Option<String>,
value: Option<String>,
style: Option<ButtonStyle>,
confirm: Option<ConfirmationDialogue>,
accessibility_label: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ButtonElementBuilder {
text: Option<PlainTextInput>,
action_id: Option<String>,
url: Option<String>,
value: Option<String>,
style: Option<ButtonStyle>,
confirm: Option<ConfirmationDialogue>,
accessibility_label: Option<String>,
extensions: Map<String, Value>,
}
impl Default for ButtonElementBuilder {
fn default() -> Self {
Self {
text: None,
action_id: None,
url: None,
value: None,
style: None,
confirm: None,
accessibility_label: None,
extensions: Map::new(),
}
}
}
impl ButtonElement {
pub fn builder() -> ButtonElementBuilder {
ButtonElementBuilder::default()
}
pub fn into_builder(self) -> ButtonElementBuilder {
ButtonElementBuilder {
text: Some(self.text.into()),
action_id: self.action_id,
url: self.url,
value: self.value,
style: self.style,
confirm: self.confirm,
accessibility_label: self.accessibility_label,
extensions: self.extensions,
}
}
pub fn text(&self) -> &PlainText {
&self.text
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn url(&self) -> Option<&str> {
self.url.as_deref()
}
pub fn value(&self) -> Option<&str> {
self.value.as_deref()
}
pub fn style(&self) -> Option<ButtonStyle> {
self.style
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn accessibility_label(&self) -> Option<&str> {
self.accessibility_label.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "button")?;
map.serialize_entry("text", &self.text)?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.url {
map.serialize_entry("url", value)?;
}
if let Some(value) = &self.value {
map.serialize_entry("value", value)?;
}
if let Some(value) = &self.style {
map.serialize_entry("style", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.accessibility_label {
map.serialize_entry("accessibility_label", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ButtonElementBuilder {
pub fn text(mut self, value: impl Into<PlainTextInput>) -> Self {
self.text = Some(value.into());
self
}
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn url(mut self, value: impl Into<String>) -> Self {
self.url = Some(value.into());
self
}
pub fn clear_url(mut self) -> Self {
self.url = None;
self
}
pub fn value(mut self, value: impl Into<String>) -> Self {
self.value = Some(value.into());
self
}
pub fn clear_value(mut self) -> Self {
self.value = None;
self
}
pub fn style(mut self, value: ButtonStyle) -> Self {
self.style = Some(value);
self
}
pub fn clear_style(mut self) -> Self {
self.style = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn accessibility_label(mut self, value: impl Into<String>) -> Self {
self.accessibility_label = Some(value.into());
self
}
pub fn clear_accessibility_label(mut self) -> Self {
self.accessibility_label = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ButtonElement, ValidationError> {
let text = wire::required(
self.text
.map(|v| v.resolve().map_err(|e| e.at("ButtonElement.text")))
.transpose()?,
"ButtonElement.text",
)?;
let action_id = self.action_id;
let url = self.url;
let value = self.value;
let style = self.style;
let confirm = self.confirm;
let accessibility_label = self.accessibility_label;
wire::extensions(
&self.extensions,
&[
"text",
"action_id",
"url",
"value",
"style",
"confirm",
"accessibility_label",
],
"ButtonElement",
)?;
let value = ButtonElement {
text,
action_id,
url,
value,
style,
confirm,
accessibility_label,
extensions: self.extensions,
};
{
let v = &value.text;
crate::rules::length(
v.text().chars().count(),
None,
Some(75),
"ButtonElement.text",
)?;
}
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"ButtonElement.action_id",
)?;
}
if let Some(v) = &value.url {
crate::rules::length(v.chars().count(), None, Some(3000), "ButtonElement.url")?;
}
if let Some(v) = &value.value {
crate::rules::length(v.chars().count(), None, Some(2000), "ButtonElement.value")?;
}
if let Some(v) = &value.accessibility_label {
crate::rules::length(
v.chars().count(),
None,
Some(75),
"ButtonElement.accessibility_label",
)?;
}
Ok(value)
}
}
impl Serialize for ButtonElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ButtonElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "button", path)?;
crate::rules::coerce_text(map.get_mut("text"), "plain_text");
let text = wire::field::<PlainText>(&mut map, "text", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let url = wire::field::<String>(&mut map, "url", path)?;
let value = wire::field::<String>(&mut map, "value", path)?;
let style = wire::field::<ButtonStyle>(&mut map, "style", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let accessibility_label = wire::field::<String>(&mut map, "accessibility_label", path)?;
ButtonElementBuilder {
text: text.map(Into::into),
action_id,
url,
value,
style,
confirm,
accessibility_label,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ButtonElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ButtonElement")
}
}
impl<'de> Deserialize<'de> for ButtonElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ChannelMultiSelectElement {
action_id: Option<String>,
initial_channels: Option<Vec<String>>,
confirm: Option<ConfirmationDialogue>,
max_selected_items: Option<i64>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ChannelMultiSelectElementBuilder {
action_id: Option<String>,
initial_channels: Option<Vec<String>>,
confirm: Option<ConfirmationDialogue>,
max_selected_items: Option<i64>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for ChannelMultiSelectElementBuilder {
fn default() -> Self {
Self {
action_id: None,
initial_channels: None,
confirm: None,
max_selected_items: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl ChannelMultiSelectElement {
pub fn builder() -> ChannelMultiSelectElementBuilder {
ChannelMultiSelectElementBuilder::default()
}
pub fn into_builder(self) -> ChannelMultiSelectElementBuilder {
ChannelMultiSelectElementBuilder {
action_id: self.action_id,
initial_channels: self.initial_channels,
confirm: self.confirm,
max_selected_items: self.max_selected_items,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn initial_channels(&self) -> Option<&[String]> {
self.initial_channels.as_deref()
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn max_selected_items(&self) -> Option<i64> {
self.max_selected_items
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "multi_channels_select")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.initial_channels {
map.serialize_entry("initial_channels", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.max_selected_items {
map.serialize_entry("max_selected_items", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ChannelMultiSelectElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn initial_channels<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<String>,
{
self.initial_channels = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn initial_channel(mut self, value: impl Into<String>) -> Self {
self.initial_channels
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_initial_channels(mut self) -> Self {
self.initial_channels = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn max_selected_items(mut self, value: i64) -> Self {
self.max_selected_items = Some(value);
self
}
pub fn clear_max_selected_items(mut self) -> Self {
self.max_selected_items = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ChannelMultiSelectElement, ValidationError> {
let action_id = self.action_id;
let initial_channels = self.initial_channels;
let confirm = self.confirm;
let max_selected_items = self.max_selected_items;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("ChannelMultiSelectElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"initial_channels",
"confirm",
"max_selected_items",
"focus_on_load",
"placeholder",
],
"ChannelMultiSelectElement",
)?;
let value = ChannelMultiSelectElement {
action_id,
initial_channels,
confirm,
max_selected_items,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"ChannelMultiSelectElement.action_id",
)?;
}
if let Some(v) = &value.max_selected_items {
if *v < 1 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"ChannelMultiSelectElement.max_selected_items",
"number outside field bounds",
));
}
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"ChannelMultiSelectElement.placeholder",
)?;
}
Ok(value)
}
}
impl Serialize for ChannelMultiSelectElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ChannelMultiSelectElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "multi_channels_select", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let initial_channels = wire::field::<Vec<String>>(&mut map, "initial_channels", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let max_selected_items = wire::field::<i64>(&mut map, "max_selected_items", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
ChannelMultiSelectElementBuilder {
action_id,
initial_channels,
confirm,
max_selected_items,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ChannelMultiSelectElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ChannelMultiSelectElement")
}
}
impl<'de> Deserialize<'de> for ChannelMultiSelectElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ChannelSelectElement {
action_id: Option<String>,
initial_channel: Option<String>,
response_url_enabled: Option<bool>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ChannelSelectElementBuilder {
action_id: Option<String>,
initial_channel: Option<String>,
response_url_enabled: Option<bool>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for ChannelSelectElementBuilder {
fn default() -> Self {
Self {
action_id: None,
initial_channel: None,
response_url_enabled: None,
confirm: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl ChannelSelectElement {
pub fn builder() -> ChannelSelectElementBuilder {
ChannelSelectElementBuilder::default()
}
pub fn into_builder(self) -> ChannelSelectElementBuilder {
ChannelSelectElementBuilder {
action_id: self.action_id,
initial_channel: self.initial_channel,
response_url_enabled: self.response_url_enabled,
confirm: self.confirm,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn initial_channel(&self) -> Option<&str> {
self.initial_channel.as_deref()
}
pub fn response_url_enabled(&self) -> Option<bool> {
self.response_url_enabled
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "channels_select")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.initial_channel {
map.serialize_entry("initial_channel", value)?;
}
if let Some(value) = &self.response_url_enabled {
map.serialize_entry("response_url_enabled", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ChannelSelectElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn initial_channel(mut self, value: impl Into<String>) -> Self {
self.initial_channel = Some(value.into());
self
}
pub fn clear_initial_channel(mut self) -> Self {
self.initial_channel = None;
self
}
pub fn response_url_enabled(mut self, value: bool) -> Self {
self.response_url_enabled = Some(value);
self
}
pub fn clear_response_url_enabled(mut self) -> Self {
self.response_url_enabled = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ChannelSelectElement, ValidationError> {
let action_id = self.action_id;
let initial_channel = self.initial_channel;
let response_url_enabled = self.response_url_enabled;
let confirm = self.confirm;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("ChannelSelectElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"initial_channel",
"response_url_enabled",
"confirm",
"focus_on_load",
"placeholder",
],
"ChannelSelectElement",
)?;
let value = ChannelSelectElement {
action_id,
initial_channel,
response_url_enabled,
confirm,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"ChannelSelectElement.action_id",
)?;
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"ChannelSelectElement.placeholder",
)?;
}
Ok(value)
}
}
impl Serialize for ChannelSelectElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ChannelSelectElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "channels_select", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let initial_channel = wire::field::<String>(&mut map, "initial_channel", path)?;
let response_url_enabled = wire::field::<bool>(&mut map, "response_url_enabled", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
ChannelSelectElementBuilder {
action_id,
initial_channel,
response_url_enabled,
confirm,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ChannelSelectElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ChannelSelectElement")
}
}
impl<'de> Deserialize<'de> for ChannelSelectElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct CheckboxesElement {
action_id: Option<String>,
options: Vec<SelectOption>,
initial_options: Option<Vec<SelectOption>>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct CheckboxesElementBuilder {
action_id: Option<String>,
options: Option<Vec<SelectOption>>,
initial_options: Option<Vec<SelectOption>>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
extensions: Map<String, Value>,
}
impl Default for CheckboxesElementBuilder {
fn default() -> Self {
Self {
action_id: None,
options: None,
initial_options: None,
confirm: None,
focus_on_load: None,
extensions: Map::new(),
}
}
}
impl CheckboxesElement {
pub fn builder() -> CheckboxesElementBuilder {
CheckboxesElementBuilder::default()
}
pub fn into_builder(self) -> CheckboxesElementBuilder {
CheckboxesElementBuilder {
action_id: self.action_id,
options: Some(self.options),
initial_options: self.initial_options,
confirm: self.confirm,
focus_on_load: self.focus_on_load,
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn options(&self) -> &[SelectOption] {
&self.options
}
pub fn initial_options(&self) -> Option<&[SelectOption]> {
self.initial_options.as_deref()
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "checkboxes")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
map.serialize_entry("options", &self.options)?;
if let Some(value) = &self.initial_options {
map.serialize_entry("initial_options", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl CheckboxesElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn options<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<SelectOption>,
{
self.options = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn option(mut self, value: impl Into<SelectOption>) -> Self {
self.options.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn initial_options<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<SelectOption>,
{
self.initial_options = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn initial_option(mut self, value: impl Into<SelectOption>) -> Self {
self.initial_options
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_initial_options(mut self) -> Self {
self.initial_options = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<CheckboxesElement, ValidationError> {
let action_id = self.action_id;
let options = wire::required(self.options, "CheckboxesElement.options")?;
let initial_options = self.initial_options;
let confirm = self.confirm;
let focus_on_load = self.focus_on_load;
wire::extensions(
&self.extensions,
&[
"action_id",
"options",
"initial_options",
"confirm",
"focus_on_load",
],
"CheckboxesElement",
)?;
let value = CheckboxesElement {
action_id,
options,
initial_options,
confirm,
focus_on_load,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"CheckboxesElement.action_id",
)?;
}
{
let v = &value.options;
crate::rules::length(v.len(), Some(1), Some(10), "CheckboxesElement.options")?;
}
Ok(value)
}
}
impl Serialize for CheckboxesElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for CheckboxesElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "checkboxes", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let options = wire::field::<Vec<SelectOption>>(&mut map, "options", path)?;
let initial_options = wire::field::<Vec<SelectOption>>(&mut map, "initial_options", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
CheckboxesElementBuilder {
action_id,
options,
initial_options,
confirm,
focus_on_load,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for CheckboxesElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "CheckboxesElement")
}
}
impl<'de> Deserialize<'de> for CheckboxesElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ConversationMultiSelectElement {
action_id: Option<String>,
initial_conversations: Option<Vec<String>>,
default_to_current_conversation: Option<bool>,
filter: Option<ConversationFilter>,
confirm: Option<ConfirmationDialogue>,
max_selected_items: Option<i64>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ConversationMultiSelectElementBuilder {
action_id: Option<String>,
initial_conversations: Option<Vec<String>>,
default_to_current_conversation: Option<bool>,
filter: Option<ConversationFilter>,
confirm: Option<ConfirmationDialogue>,
max_selected_items: Option<i64>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for ConversationMultiSelectElementBuilder {
fn default() -> Self {
Self {
action_id: None,
initial_conversations: None,
default_to_current_conversation: None,
filter: None,
confirm: None,
max_selected_items: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl ConversationMultiSelectElement {
pub fn builder() -> ConversationMultiSelectElementBuilder {
ConversationMultiSelectElementBuilder::default()
}
pub fn into_builder(self) -> ConversationMultiSelectElementBuilder {
ConversationMultiSelectElementBuilder {
action_id: self.action_id,
initial_conversations: self.initial_conversations,
default_to_current_conversation: self.default_to_current_conversation,
filter: self.filter,
confirm: self.confirm,
max_selected_items: self.max_selected_items,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn initial_conversations(&self) -> Option<&[String]> {
self.initial_conversations.as_deref()
}
pub fn default_to_current_conversation(&self) -> Option<bool> {
self.default_to_current_conversation
}
pub fn filter(&self) -> Option<&ConversationFilter> {
self.filter.as_ref()
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn max_selected_items(&self) -> Option<i64> {
self.max_selected_items
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "multi_conversations_select")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.initial_conversations {
map.serialize_entry("initial_conversations", value)?;
}
if let Some(value) = &self.default_to_current_conversation {
map.serialize_entry("default_to_current_conversation", value)?;
}
if let Some(value) = &self.filter {
map.serialize_entry("filter", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.max_selected_items {
map.serialize_entry("max_selected_items", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ConversationMultiSelectElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn initial_conversations<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<String>,
{
self.initial_conversations = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn initial_conversation(mut self, value: impl Into<String>) -> Self {
self.initial_conversations
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_initial_conversations(mut self) -> Self {
self.initial_conversations = None;
self
}
pub fn default_to_current_conversation(mut self, value: bool) -> Self {
self.default_to_current_conversation = Some(value);
self
}
pub fn clear_default_to_current_conversation(mut self) -> Self {
self.default_to_current_conversation = None;
self
}
pub fn filter(mut self, value: impl Into<ConversationFilter>) -> Self {
self.filter = Some(value.into());
self
}
pub fn clear_filter(mut self) -> Self {
self.filter = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn max_selected_items(mut self, value: i64) -> Self {
self.max_selected_items = Some(value);
self
}
pub fn clear_max_selected_items(mut self) -> Self {
self.max_selected_items = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ConversationMultiSelectElement, ValidationError> {
let action_id = self.action_id;
let initial_conversations = self.initial_conversations;
let default_to_current_conversation = self.default_to_current_conversation;
let filter = self.filter;
let confirm = self.confirm;
let max_selected_items = self.max_selected_items;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("ConversationMultiSelectElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"initial_conversations",
"default_to_current_conversation",
"filter",
"confirm",
"max_selected_items",
"focus_on_load",
"placeholder",
],
"ConversationMultiSelectElement",
)?;
let value = ConversationMultiSelectElement {
action_id,
initial_conversations,
default_to_current_conversation,
filter,
confirm,
max_selected_items,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"ConversationMultiSelectElement.action_id",
)?;
}
if let Some(v) = &value.max_selected_items {
if *v < 1 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"ConversationMultiSelectElement.max_selected_items",
"number outside field bounds",
));
}
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"ConversationMultiSelectElement.placeholder",
)?;
}
Ok(value)
}
}
impl Serialize for ConversationMultiSelectElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ConversationMultiSelectElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "multi_conversations_select", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let initial_conversations =
wire::field::<Vec<String>>(&mut map, "initial_conversations", path)?;
let default_to_current_conversation =
wire::field::<bool>(&mut map, "default_to_current_conversation", path)?;
let filter = wire::field::<ConversationFilter>(&mut map, "filter", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let max_selected_items = wire::field::<i64>(&mut map, "max_selected_items", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
ConversationMultiSelectElementBuilder {
action_id,
initial_conversations,
default_to_current_conversation,
filter,
confirm,
max_selected_items,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ConversationMultiSelectElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ConversationMultiSelectElement")
}
}
impl<'de> Deserialize<'de> for ConversationMultiSelectElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ConversationSelectElement {
action_id: Option<String>,
initial_conversation: Option<String>,
default_to_current_conversation: Option<bool>,
filter: Option<ConversationFilter>,
response_url_enabled: Option<bool>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ConversationSelectElementBuilder {
action_id: Option<String>,
initial_conversation: Option<String>,
default_to_current_conversation: Option<bool>,
filter: Option<ConversationFilter>,
response_url_enabled: Option<bool>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for ConversationSelectElementBuilder {
fn default() -> Self {
Self {
action_id: None,
initial_conversation: None,
default_to_current_conversation: None,
filter: None,
response_url_enabled: None,
confirm: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl ConversationSelectElement {
pub fn builder() -> ConversationSelectElementBuilder {
ConversationSelectElementBuilder::default()
}
pub fn into_builder(self) -> ConversationSelectElementBuilder {
ConversationSelectElementBuilder {
action_id: self.action_id,
initial_conversation: self.initial_conversation,
default_to_current_conversation: self.default_to_current_conversation,
filter: self.filter,
response_url_enabled: self.response_url_enabled,
confirm: self.confirm,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn initial_conversation(&self) -> Option<&str> {
self.initial_conversation.as_deref()
}
pub fn default_to_current_conversation(&self) -> Option<bool> {
self.default_to_current_conversation
}
pub fn filter(&self) -> Option<&ConversationFilter> {
self.filter.as_ref()
}
pub fn response_url_enabled(&self) -> Option<bool> {
self.response_url_enabled
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "conversations_select")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.initial_conversation {
map.serialize_entry("initial_conversation", value)?;
}
if let Some(value) = &self.default_to_current_conversation {
map.serialize_entry("default_to_current_conversation", value)?;
}
if let Some(value) = &self.filter {
map.serialize_entry("filter", value)?;
}
if let Some(value) = &self.response_url_enabled {
map.serialize_entry("response_url_enabled", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ConversationSelectElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn initial_conversation(mut self, value: impl Into<String>) -> Self {
self.initial_conversation = Some(value.into());
self
}
pub fn clear_initial_conversation(mut self) -> Self {
self.initial_conversation = None;
self
}
pub fn default_to_current_conversation(mut self, value: bool) -> Self {
self.default_to_current_conversation = Some(value);
self
}
pub fn clear_default_to_current_conversation(mut self) -> Self {
self.default_to_current_conversation = None;
self
}
pub fn filter(mut self, value: impl Into<ConversationFilter>) -> Self {
self.filter = Some(value.into());
self
}
pub fn clear_filter(mut self) -> Self {
self.filter = None;
self
}
pub fn response_url_enabled(mut self, value: bool) -> Self {
self.response_url_enabled = Some(value);
self
}
pub fn clear_response_url_enabled(mut self) -> Self {
self.response_url_enabled = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ConversationSelectElement, ValidationError> {
let action_id = self.action_id;
let initial_conversation = self.initial_conversation;
let default_to_current_conversation = self.default_to_current_conversation;
let filter = self.filter;
let response_url_enabled = self.response_url_enabled;
let confirm = self.confirm;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("ConversationSelectElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"initial_conversation",
"default_to_current_conversation",
"filter",
"response_url_enabled",
"confirm",
"focus_on_load",
"placeholder",
],
"ConversationSelectElement",
)?;
let value = ConversationSelectElement {
action_id,
initial_conversation,
default_to_current_conversation,
filter,
response_url_enabled,
confirm,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"ConversationSelectElement.action_id",
)?;
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"ConversationSelectElement.placeholder",
)?;
}
Ok(value)
}
}
impl Serialize for ConversationSelectElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ConversationSelectElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "conversations_select", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let initial_conversation = wire::field::<String>(&mut map, "initial_conversation", path)?;
let default_to_current_conversation =
wire::field::<bool>(&mut map, "default_to_current_conversation", path)?;
let filter = wire::field::<ConversationFilter>(&mut map, "filter", path)?;
let response_url_enabled = wire::field::<bool>(&mut map, "response_url_enabled", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
ConversationSelectElementBuilder {
action_id,
initial_conversation,
default_to_current_conversation,
filter,
response_url_enabled,
confirm,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ConversationSelectElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ConversationSelectElement")
}
}
impl<'de> Deserialize<'de> for ConversationSelectElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct DatePickerElement {
action_id: Option<String>,
initial_date: Option<String>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct DatePickerElementBuilder {
action_id: Option<String>,
initial_date: Option<String>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for DatePickerElementBuilder {
fn default() -> Self {
Self {
action_id: None,
initial_date: None,
confirm: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl DatePickerElement {
pub fn builder() -> DatePickerElementBuilder {
DatePickerElementBuilder::default()
}
pub fn into_builder(self) -> DatePickerElementBuilder {
DatePickerElementBuilder {
action_id: self.action_id,
initial_date: self.initial_date,
confirm: self.confirm,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn initial_date(&self) -> Option<&str> {
self.initial_date.as_deref()
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "datepicker")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.initial_date {
map.serialize_entry("initial_date", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl DatePickerElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn initial_date(mut self, value: impl Into<String>) -> Self {
self.initial_date = Some(value.into());
self
}
pub fn clear_initial_date(mut self) -> Self {
self.initial_date = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<DatePickerElement, ValidationError> {
let action_id = self.action_id;
let initial_date = self.initial_date;
let confirm = self.confirm;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("DatePickerElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"initial_date",
"confirm",
"focus_on_load",
"placeholder",
],
"DatePickerElement",
)?;
let value = DatePickerElement {
action_id,
initial_date,
confirm,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"DatePickerElement.action_id",
)?;
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"DatePickerElement.placeholder",
)?;
}
Ok(value)
}
}
impl Serialize for DatePickerElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for DatePickerElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "datepicker", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let initial_date = wire::field::<String>(&mut map, "initial_date", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
DatePickerElementBuilder {
action_id,
initial_date,
confirm,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for DatePickerElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "DatePickerElement")
}
}
impl<'de> Deserialize<'de> for DatePickerElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct DateTimePickerElement {
action_id: Option<String>,
initial_date_time: Option<i64>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct DateTimePickerElementBuilder {
action_id: Option<String>,
initial_date_time: Option<i64>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
extensions: Map<String, Value>,
}
impl Default for DateTimePickerElementBuilder {
fn default() -> Self {
Self {
action_id: None,
initial_date_time: None,
confirm: None,
focus_on_load: None,
extensions: Map::new(),
}
}
}
impl DateTimePickerElement {
pub fn builder() -> DateTimePickerElementBuilder {
DateTimePickerElementBuilder::default()
}
pub fn into_builder(self) -> DateTimePickerElementBuilder {
DateTimePickerElementBuilder {
action_id: self.action_id,
initial_date_time: self.initial_date_time,
confirm: self.confirm,
focus_on_load: self.focus_on_load,
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn initial_date_time(&self) -> Option<i64> {
self.initial_date_time
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "datetimepicker")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.initial_date_time {
map.serialize_entry("initial_date_time", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl DateTimePickerElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn initial_date_time(mut self, value: i64) -> Self {
self.initial_date_time = Some(value);
self
}
pub fn clear_initial_date_time(mut self) -> Self {
self.initial_date_time = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<DateTimePickerElement, ValidationError> {
let action_id = self.action_id;
let initial_date_time = self.initial_date_time;
let confirm = self.confirm;
let focus_on_load = self.focus_on_load;
wire::extensions(
&self.extensions,
&["action_id", "initial_date_time", "confirm", "focus_on_load"],
"DateTimePickerElement",
)?;
let value = DateTimePickerElement {
action_id,
initial_date_time,
confirm,
focus_on_load,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"DateTimePickerElement.action_id",
)?;
}
Ok(value)
}
}
impl Serialize for DateTimePickerElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for DateTimePickerElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "datetimepicker", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let initial_date_time = wire::field::<i64>(&mut map, "initial_date_time", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
DateTimePickerElementBuilder {
action_id,
initial_date_time,
confirm,
focus_on_load,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for DateTimePickerElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "DateTimePickerElement")
}
}
impl<'de> Deserialize<'de> for DateTimePickerElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct EmailInputElement {
action_id: Option<String>,
initial_value: Option<String>,
dispatch_action_config: Option<DispatchActionConfiguration>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct EmailInputElementBuilder {
action_id: Option<String>,
initial_value: Option<String>,
dispatch_action_config: Option<DispatchActionConfiguration>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for EmailInputElementBuilder {
fn default() -> Self {
Self {
action_id: None,
initial_value: None,
dispatch_action_config: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl EmailInputElement {
pub fn builder() -> EmailInputElementBuilder {
EmailInputElementBuilder::default()
}
pub fn into_builder(self) -> EmailInputElementBuilder {
EmailInputElementBuilder {
action_id: self.action_id,
initial_value: self.initial_value,
dispatch_action_config: self.dispatch_action_config,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn initial_value(&self) -> Option<&str> {
self.initial_value.as_deref()
}
pub fn dispatch_action_config(&self) -> Option<&DispatchActionConfiguration> {
self.dispatch_action_config.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "email_text_input")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.initial_value {
map.serialize_entry("initial_value", value)?;
}
if let Some(value) = &self.dispatch_action_config {
map.serialize_entry("dispatch_action_config", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl EmailInputElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn initial_value(mut self, value: impl Into<String>) -> Self {
self.initial_value = Some(value.into());
self
}
pub fn clear_initial_value(mut self) -> Self {
self.initial_value = None;
self
}
pub fn dispatch_action_config(mut self, value: impl Into<DispatchActionConfiguration>) -> Self {
self.dispatch_action_config = Some(value.into());
self
}
pub fn clear_dispatch_action_config(mut self) -> Self {
self.dispatch_action_config = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<EmailInputElement, ValidationError> {
let action_id = self.action_id;
let initial_value = self.initial_value;
let dispatch_action_config = self.dispatch_action_config;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("EmailInputElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"initial_value",
"dispatch_action_config",
"focus_on_load",
"placeholder",
],
"EmailInputElement",
)?;
let value = EmailInputElement {
action_id,
initial_value,
dispatch_action_config,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"EmailInputElement.action_id",
)?;
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"EmailInputElement.placeholder",
)?;
}
Ok(value)
}
}
impl Serialize for EmailInputElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for EmailInputElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "email_text_input", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let initial_value = wire::field::<String>(&mut map, "initial_value", path)?;
let dispatch_action_config =
wire::field::<DispatchActionConfiguration>(&mut map, "dispatch_action_config", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
EmailInputElementBuilder {
action_id,
initial_value,
dispatch_action_config,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for EmailInputElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "EmailInputElement")
}
}
impl<'de> Deserialize<'de> for EmailInputElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ExternalMultiSelectElement {
action_id: Option<String>,
min_query_length: Option<i64>,
initial_options: Option<Vec<SelectOption>>,
confirm: Option<ConfirmationDialogue>,
max_selected_items: Option<i64>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ExternalMultiSelectElementBuilder {
action_id: Option<String>,
min_query_length: Option<i64>,
initial_options: Option<Vec<SelectOption>>,
confirm: Option<ConfirmationDialogue>,
max_selected_items: Option<i64>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for ExternalMultiSelectElementBuilder {
fn default() -> Self {
Self {
action_id: None,
min_query_length: None,
initial_options: None,
confirm: None,
max_selected_items: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl ExternalMultiSelectElement {
pub fn builder() -> ExternalMultiSelectElementBuilder {
ExternalMultiSelectElementBuilder::default()
}
pub fn into_builder(self) -> ExternalMultiSelectElementBuilder {
ExternalMultiSelectElementBuilder {
action_id: self.action_id,
min_query_length: self.min_query_length,
initial_options: self.initial_options,
confirm: self.confirm,
max_selected_items: self.max_selected_items,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn min_query_length(&self) -> Option<i64> {
self.min_query_length
}
pub fn initial_options(&self) -> Option<&[SelectOption]> {
self.initial_options.as_deref()
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn max_selected_items(&self) -> Option<i64> {
self.max_selected_items
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "multi_external_select")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.min_query_length {
map.serialize_entry("min_query_length", value)?;
}
if let Some(value) = &self.initial_options {
map.serialize_entry("initial_options", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.max_selected_items {
map.serialize_entry("max_selected_items", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ExternalMultiSelectElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn min_query_length(mut self, value: i64) -> Self {
self.min_query_length = Some(value);
self
}
pub fn clear_min_query_length(mut self) -> Self {
self.min_query_length = None;
self
}
pub fn initial_options<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<SelectOption>,
{
self.initial_options = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn initial_option(mut self, value: impl Into<SelectOption>) -> Self {
self.initial_options
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_initial_options(mut self) -> Self {
self.initial_options = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn max_selected_items(mut self, value: i64) -> Self {
self.max_selected_items = Some(value);
self
}
pub fn clear_max_selected_items(mut self) -> Self {
self.max_selected_items = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ExternalMultiSelectElement, ValidationError> {
let action_id = self.action_id;
let min_query_length = self.min_query_length;
let initial_options = self.initial_options;
let confirm = self.confirm;
let max_selected_items = self.max_selected_items;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("ExternalMultiSelectElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"min_query_length",
"initial_options",
"confirm",
"max_selected_items",
"focus_on_load",
"placeholder",
],
"ExternalMultiSelectElement",
)?;
let value = ExternalMultiSelectElement {
action_id,
min_query_length,
initial_options,
confirm,
max_selected_items,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"ExternalMultiSelectElement.action_id",
)?;
}
if let Some(v) = &value.max_selected_items {
if *v < 1 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"ExternalMultiSelectElement.max_selected_items",
"number outside field bounds",
));
}
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"ExternalMultiSelectElement.placeholder",
)?;
}
Ok(value)
}
}
impl Serialize for ExternalMultiSelectElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ExternalMultiSelectElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "multi_external_select", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let min_query_length = wire::field::<i64>(&mut map, "min_query_length", path)?;
let initial_options = wire::field::<Vec<SelectOption>>(&mut map, "initial_options", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let max_selected_items = wire::field::<i64>(&mut map, "max_selected_items", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
ExternalMultiSelectElementBuilder {
action_id,
min_query_length,
initial_options,
confirm,
max_selected_items,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ExternalMultiSelectElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ExternalMultiSelectElement")
}
}
impl<'de> Deserialize<'de> for ExternalMultiSelectElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ExternalSelectElement {
action_id: Option<String>,
min_query_length: Option<i64>,
initial_option: Option<SelectOption>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ExternalSelectElementBuilder {
action_id: Option<String>,
min_query_length: Option<i64>,
initial_option: Option<SelectOption>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for ExternalSelectElementBuilder {
fn default() -> Self {
Self {
action_id: None,
min_query_length: None,
initial_option: None,
confirm: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl ExternalSelectElement {
pub fn builder() -> ExternalSelectElementBuilder {
ExternalSelectElementBuilder::default()
}
pub fn into_builder(self) -> ExternalSelectElementBuilder {
ExternalSelectElementBuilder {
action_id: self.action_id,
min_query_length: self.min_query_length,
initial_option: self.initial_option,
confirm: self.confirm,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn min_query_length(&self) -> Option<i64> {
self.min_query_length
}
pub fn initial_option(&self) -> Option<&SelectOption> {
self.initial_option.as_ref()
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "external_select")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.min_query_length {
map.serialize_entry("min_query_length", value)?;
}
if let Some(value) = &self.initial_option {
map.serialize_entry("initial_option", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ExternalSelectElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn min_query_length(mut self, value: i64) -> Self {
self.min_query_length = Some(value);
self
}
pub fn clear_min_query_length(mut self) -> Self {
self.min_query_length = None;
self
}
pub fn initial_option(mut self, value: impl Into<SelectOption>) -> Self {
self.initial_option = Some(value.into());
self
}
pub fn clear_initial_option(mut self) -> Self {
self.initial_option = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ExternalSelectElement, ValidationError> {
let action_id = self.action_id;
let min_query_length = self.min_query_length;
let initial_option = self.initial_option;
let confirm = self.confirm;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("ExternalSelectElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"min_query_length",
"initial_option",
"confirm",
"focus_on_load",
"placeholder",
],
"ExternalSelectElement",
)?;
let value = ExternalSelectElement {
action_id,
min_query_length,
initial_option,
confirm,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"ExternalSelectElement.action_id",
)?;
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"ExternalSelectElement.placeholder",
)?;
}
Ok(value)
}
}
impl Serialize for ExternalSelectElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ExternalSelectElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "external_select", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let min_query_length = wire::field::<i64>(&mut map, "min_query_length", path)?;
let initial_option = wire::field::<SelectOption>(&mut map, "initial_option", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
ExternalSelectElementBuilder {
action_id,
min_query_length,
initial_option,
confirm,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ExternalSelectElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ExternalSelectElement")
}
}
impl<'de> Deserialize<'de> for ExternalSelectElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct FeedbackButtonsElement {
positive_button: FeedbackButton,
negative_button: FeedbackButton,
action_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct FeedbackButtonsElementBuilder {
positive_button: Option<FeedbackButton>,
negative_button: Option<FeedbackButton>,
action_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for FeedbackButtonsElementBuilder {
fn default() -> Self {
Self {
positive_button: None,
negative_button: None,
action_id: None,
extensions: Map::new(),
}
}
}
impl FeedbackButtonsElement {
pub fn builder() -> FeedbackButtonsElementBuilder {
FeedbackButtonsElementBuilder::default()
}
pub fn into_builder(self) -> FeedbackButtonsElementBuilder {
FeedbackButtonsElementBuilder {
positive_button: Some(self.positive_button),
negative_button: Some(self.negative_button),
action_id: self.action_id,
extensions: self.extensions,
}
}
pub fn positive_button(&self) -> &FeedbackButton {
&self.positive_button
}
pub fn negative_button(&self) -> &FeedbackButton {
&self.negative_button
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "feedback_buttons")?;
map.serialize_entry("positive_button", &self.positive_button)?;
map.serialize_entry("negative_button", &self.negative_button)?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl FeedbackButtonsElementBuilder {
pub fn positive_button(mut self, value: impl Into<FeedbackButton>) -> Self {
self.positive_button = Some(value.into());
self
}
pub fn negative_button(mut self, value: impl Into<FeedbackButton>) -> Self {
self.negative_button = Some(value.into());
self
}
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<FeedbackButtonsElement, ValidationError> {
let positive_button = wire::required(
self.positive_button,
"FeedbackButtonsElement.positive_button",
)?;
let negative_button = wire::required(
self.negative_button,
"FeedbackButtonsElement.negative_button",
)?;
let action_id = self.action_id;
wire::extensions(
&self.extensions,
&["positive_button", "negative_button", "action_id"],
"FeedbackButtonsElement",
)?;
let value = FeedbackButtonsElement {
positive_button,
negative_button,
action_id,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"FeedbackButtonsElement.action_id",
)?;
}
Ok(value)
}
}
impl Serialize for FeedbackButtonsElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for FeedbackButtonsElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "feedback_buttons", path)?;
let positive_button = wire::field::<FeedbackButton>(&mut map, "positive_button", path)?;
let negative_button = wire::field::<FeedbackButton>(&mut map, "negative_button", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
FeedbackButtonsElementBuilder {
positive_button,
negative_button,
action_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for FeedbackButtonsElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "FeedbackButtonsElement")
}
}
impl<'de> Deserialize<'de> for FeedbackButtonsElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct FileInputElement {
action_id: Option<String>,
filetypes: Option<Vec<String>>,
max_files: Option<i64>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct FileInputElementBuilder {
action_id: Option<String>,
filetypes: Option<Vec<String>>,
max_files: Option<i64>,
extensions: Map<String, Value>,
}
impl Default for FileInputElementBuilder {
fn default() -> Self {
Self {
action_id: None,
filetypes: None,
max_files: None,
extensions: Map::new(),
}
}
}
impl FileInputElement {
pub fn builder() -> FileInputElementBuilder {
FileInputElementBuilder::default()
}
pub fn into_builder(self) -> FileInputElementBuilder {
FileInputElementBuilder {
action_id: self.action_id,
filetypes: self.filetypes,
max_files: self.max_files,
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn filetypes(&self) -> Option<&[String]> {
self.filetypes.as_deref()
}
pub fn max_files(&self) -> Option<i64> {
self.max_files
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "file_input")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.filetypes {
map.serialize_entry("filetypes", value)?;
}
if let Some(value) = &self.max_files {
map.serialize_entry("max_files", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl FileInputElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn filetypes<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<String>,
{
self.filetypes = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn filetype(mut self, value: impl Into<String>) -> Self {
self.filetypes
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_filetypes(mut self) -> Self {
self.filetypes = None;
self
}
pub fn max_files(mut self, value: i64) -> Self {
self.max_files = Some(value);
self
}
pub fn clear_max_files(mut self) -> Self {
self.max_files = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<FileInputElement, ValidationError> {
let action_id = self.action_id;
let filetypes = self.filetypes;
let max_files = self.max_files;
wire::extensions(
&self.extensions,
&["action_id", "filetypes", "max_files"],
"FileInputElement",
)?;
let value = FileInputElement {
action_id,
filetypes,
max_files,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"FileInputElement.action_id",
)?;
}
if let Some(v) = &value.max_files {
if *v < 1 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"FileInputElement.max_files",
"number outside field bounds",
));
}
if *v > 10 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"FileInputElement.max_files",
"number outside field bounds",
));
}
}
Ok(value)
}
}
impl Serialize for FileInputElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for FileInputElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "file_input", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let filetypes = wire::field::<Vec<String>>(&mut map, "filetypes", path)?;
let max_files = wire::field::<i64>(&mut map, "max_files", path)?;
FileInputElementBuilder {
action_id,
filetypes,
max_files,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for FileInputElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "FileInputElement")
}
}
impl<'de> Deserialize<'de> for FileInputElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct IconButtonElement {
text: PlainText,
icon: IconButtonIcon,
action_id: Option<String>,
value: Option<String>,
confirm: Option<ConfirmationDialogue>,
accessibility_label: Option<String>,
visible_to_user_ids: Option<Vec<String>>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct IconButtonElementBuilder {
text: Option<PlainTextInput>,
icon: Option<IconButtonIcon>,
action_id: Option<String>,
value: Option<String>,
confirm: Option<ConfirmationDialogue>,
accessibility_label: Option<String>,
visible_to_user_ids: Option<Vec<String>>,
extensions: Map<String, Value>,
}
impl Default for IconButtonElementBuilder {
fn default() -> Self {
Self {
text: None,
icon: Some(IconButtonIcon::Trash),
action_id: None,
value: None,
confirm: None,
accessibility_label: None,
visible_to_user_ids: None,
extensions: Map::new(),
}
}
}
impl IconButtonElement {
pub fn builder() -> IconButtonElementBuilder {
IconButtonElementBuilder::default()
}
pub fn into_builder(self) -> IconButtonElementBuilder {
IconButtonElementBuilder {
text: Some(self.text.into()),
icon: Some(self.icon),
action_id: self.action_id,
value: self.value,
confirm: self.confirm,
accessibility_label: self.accessibility_label,
visible_to_user_ids: self.visible_to_user_ids,
extensions: self.extensions,
}
}
pub fn text(&self) -> &PlainText {
&self.text
}
pub fn icon(&self) -> IconButtonIcon {
self.icon
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn value(&self) -> Option<&str> {
self.value.as_deref()
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn accessibility_label(&self) -> Option<&str> {
self.accessibility_label.as_deref()
}
pub fn visible_to_user_ids(&self) -> Option<&[String]> {
self.visible_to_user_ids.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "icon_button")?;
map.serialize_entry("text", &self.text)?;
map.serialize_entry("icon", &self.icon)?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.value {
map.serialize_entry("value", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.accessibility_label {
map.serialize_entry("accessibility_label", value)?;
}
if let Some(value) = &self.visible_to_user_ids {
map.serialize_entry("visible_to_user_ids", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl IconButtonElementBuilder {
pub fn text(mut self, value: impl Into<PlainTextInput>) -> Self {
self.text = Some(value.into());
self
}
pub fn icon(mut self, value: IconButtonIcon) -> Self {
self.icon = Some(value);
self
}
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn value(mut self, value: impl Into<String>) -> Self {
self.value = Some(value.into());
self
}
pub fn clear_value(mut self) -> Self {
self.value = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn accessibility_label(mut self, value: impl Into<String>) -> Self {
self.accessibility_label = Some(value.into());
self
}
pub fn clear_accessibility_label(mut self) -> Self {
self.accessibility_label = None;
self
}
pub fn visible_to_user_ids<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<String>,
{
self.visible_to_user_ids = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn visible_to_user_id(mut self, value: impl Into<String>) -> Self {
self.visible_to_user_ids
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_visible_to_user_ids(mut self) -> Self {
self.visible_to_user_ids = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<IconButtonElement, ValidationError> {
let text = wire::required(
self.text
.map(|v| v.resolve().map_err(|e| e.at("IconButtonElement.text")))
.transpose()?,
"IconButtonElement.text",
)?;
let icon = wire::required(self.icon, "IconButtonElement.icon")?;
let action_id = self.action_id;
let value = self.value;
let confirm = self.confirm;
let accessibility_label = self.accessibility_label;
let visible_to_user_ids = self.visible_to_user_ids;
wire::extensions(
&self.extensions,
&[
"text",
"icon",
"action_id",
"value",
"confirm",
"accessibility_label",
"visible_to_user_ids",
],
"IconButtonElement",
)?;
let value = IconButtonElement {
text,
icon,
action_id,
value,
confirm,
accessibility_label,
visible_to_user_ids,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"IconButtonElement.action_id",
)?;
}
if let Some(v) = &value.value {
crate::rules::length(
v.chars().count(),
None,
Some(2000),
"IconButtonElement.value",
)?;
}
if let Some(v) = &value.accessibility_label {
crate::rules::length(
v.chars().count(),
None,
Some(75),
"IconButtonElement.accessibility_label",
)?;
}
if let Some(v) = &value.visible_to_user_ids {
crate::rules::length(
v.len(),
None,
Some(10),
"IconButtonElement.visible_to_user_ids",
)?;
}
Ok(value)
}
}
impl Serialize for IconButtonElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for IconButtonElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "icon_button", path)?;
crate::rules::coerce_text(map.get_mut("text"), "plain_text");
let text = wire::field::<PlainText>(&mut map, "text", path)?;
if !map.contains_key("icon") {
map.insert("icon".into(), serde_json::json!("trash"));
}
let icon = wire::field::<IconButtonIcon>(&mut map, "icon", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let value = wire::field::<String>(&mut map, "value", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let accessibility_label = wire::field::<String>(&mut map, "accessibility_label", path)?;
let visible_to_user_ids =
wire::field::<Vec<String>>(&mut map, "visible_to_user_ids", path)?;
IconButtonElementBuilder {
text: text.map(Into::into),
icon,
action_id,
value,
confirm,
accessibility_label,
visible_to_user_ids,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for IconButtonElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "IconButtonElement")
}
}
impl<'de> Deserialize<'de> for IconButtonElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ImageElement {
alt_text: String,
image_url: Option<String>,
slack_file: Option<SlackFile>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ImageElementBuilder {
alt_text: Option<String>,
image_url: Option<String>,
slack_file: Option<SlackFile>,
extensions: Map<String, Value>,
}
impl Default for ImageElementBuilder {
fn default() -> Self {
Self {
alt_text: None,
image_url: None,
slack_file: None,
extensions: Map::new(),
}
}
}
impl ImageElement {
pub fn builder() -> ImageElementBuilder {
ImageElementBuilder::default()
}
pub fn into_builder(self) -> ImageElementBuilder {
ImageElementBuilder {
alt_text: Some(self.alt_text),
image_url: self.image_url,
slack_file: self.slack_file,
extensions: self.extensions,
}
}
pub fn alt_text(&self) -> &str {
&self.alt_text
}
pub fn image_url(&self) -> Option<&str> {
self.image_url.as_deref()
}
pub fn slack_file(&self) -> Option<&SlackFile> {
self.slack_file.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "image")?;
map.serialize_entry("alt_text", &self.alt_text)?;
if let Some(value) = &self.image_url {
map.serialize_entry("image_url", value)?;
}
if let Some(value) = &self.slack_file {
map.serialize_entry("slack_file", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ImageElementBuilder {
pub fn alt_text(mut self, value: impl Into<String>) -> Self {
self.alt_text = Some(value.into());
self
}
pub fn image_url(mut self, value: impl Into<String>) -> Self {
self.image_url = Some(value.into());
self
}
pub fn clear_image_url(mut self) -> Self {
self.image_url = None;
self
}
pub fn slack_file(mut self, value: impl Into<SlackFile>) -> Self {
self.slack_file = Some(value.into());
self
}
pub fn clear_slack_file(mut self) -> Self {
self.slack_file = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ImageElement, ValidationError> {
let alt_text = wire::required(self.alt_text, "ImageElement.alt_text")?;
let image_url = self.image_url;
let slack_file = self.slack_file;
wire::extensions(
&self.extensions,
&["alt_text", "image_url", "slack_file"],
"ImageElement",
)?;
let value = ImageElement {
alt_text,
image_url,
slack_file,
extensions: self.extensions,
};
{
let v = &value.alt_text;
crate::rules::length(v.chars().count(), None, Some(2000), "ImageElement.alt_text")?;
}
if let Some(v) = &value.image_url {
crate::rules::length(
v.chars().count(),
None,
Some(3000),
"ImageElement.image_url",
)?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "ImageElement", e.to_string())
})?;
crate::rules::validate("ImageElement", &wire, "ImageElement")?;
Ok(value)
}
}
impl Serialize for ImageElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ImageElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "image", path)?;
let alt_text = wire::field::<String>(&mut map, "alt_text", path)?;
let image_url = wire::field::<String>(&mut map, "image_url", path)?;
let slack_file = wire::field::<SlackFile>(&mut map, "slack_file", path)?;
ImageElementBuilder {
alt_text,
image_url,
slack_file,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ImageElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ImageElement")
}
}
impl<'de> Deserialize<'de> for ImageElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct NumberInputElement {
action_id: Option<String>,
is_decimal_allowed: bool,
initial_value: Option<String>,
min_value: Option<f64>,
max_value: Option<f64>,
dispatch_action_config: Option<DispatchActionConfiguration>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct NumberInputElementBuilder {
action_id: Option<String>,
is_decimal_allowed: Option<bool>,
initial_value: Option<String>,
min_value: Option<f64>,
max_value: Option<f64>,
dispatch_action_config: Option<DispatchActionConfiguration>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for NumberInputElementBuilder {
fn default() -> Self {
Self {
action_id: None,
is_decimal_allowed: None,
initial_value: None,
min_value: None,
max_value: None,
dispatch_action_config: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl NumberInputElement {
pub fn builder() -> NumberInputElementBuilder {
NumberInputElementBuilder::default()
}
pub fn into_builder(self) -> NumberInputElementBuilder {
NumberInputElementBuilder {
action_id: self.action_id,
is_decimal_allowed: Some(self.is_decimal_allowed),
initial_value: self.initial_value,
min_value: self.min_value,
max_value: self.max_value,
dispatch_action_config: self.dispatch_action_config,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn is_decimal_allowed(&self) -> bool {
self.is_decimal_allowed
}
pub fn initial_value(&self) -> Option<&str> {
self.initial_value.as_deref()
}
pub fn min_value(&self) -> Option<f64> {
self.min_value
}
pub fn max_value(&self) -> Option<f64> {
self.max_value
}
pub fn dispatch_action_config(&self) -> Option<&DispatchActionConfiguration> {
self.dispatch_action_config.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "number_input")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
map.serialize_entry("is_decimal_allowed", &self.is_decimal_allowed)?;
if let Some(value) = &self.initial_value {
map.serialize_entry("initial_value", value)?;
}
if let Some(value) = &self.min_value {
map.serialize_entry("min_value", value)?;
}
if let Some(value) = &self.max_value {
map.serialize_entry("max_value", value)?;
}
if let Some(value) = &self.dispatch_action_config {
map.serialize_entry("dispatch_action_config", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl NumberInputElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn is_decimal_allowed(mut self, value: bool) -> Self {
self.is_decimal_allowed = Some(value);
self
}
pub fn initial_value(mut self, value: impl Into<String>) -> Self {
self.initial_value = Some(value.into());
self
}
pub fn clear_initial_value(mut self) -> Self {
self.initial_value = None;
self
}
pub fn min_value(mut self, value: f64) -> Self {
self.min_value = Some(value);
self
}
pub fn clear_min_value(mut self) -> Self {
self.min_value = None;
self
}
pub fn max_value(mut self, value: f64) -> Self {
self.max_value = Some(value);
self
}
pub fn clear_max_value(mut self) -> Self {
self.max_value = None;
self
}
pub fn dispatch_action_config(mut self, value: impl Into<DispatchActionConfiguration>) -> Self {
self.dispatch_action_config = Some(value.into());
self
}
pub fn clear_dispatch_action_config(mut self) -> Self {
self.dispatch_action_config = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<NumberInputElement, ValidationError> {
let action_id = self.action_id;
let is_decimal_allowed = wire::required(
self.is_decimal_allowed,
"NumberInputElement.is_decimal_allowed",
)?;
let initial_value = self.initial_value;
let min_value = self.min_value;
if min_value.is_some_and(|v| !v.is_finite()) {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"NumberInputElement.min_value",
"expected a finite number",
));
}
let max_value = self.max_value;
if max_value.is_some_and(|v| !v.is_finite()) {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"NumberInputElement.max_value",
"expected a finite number",
));
}
let dispatch_action_config = self.dispatch_action_config;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("NumberInputElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"is_decimal_allowed",
"initial_value",
"min_value",
"max_value",
"dispatch_action_config",
"focus_on_load",
"placeholder",
],
"NumberInputElement",
)?;
let value = NumberInputElement {
action_id,
is_decimal_allowed,
initial_value,
min_value,
max_value,
dispatch_action_config,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"NumberInputElement.action_id",
)?;
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"NumberInputElement.placeholder",
)?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(
ErrorCategory::TypeMismatch,
"NumberInputElement",
e.to_string(),
)
})?;
crate::rules::validate("NumberInputElement", &wire, "NumberInputElement")?;
Ok(value)
}
}
impl Serialize for NumberInputElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for NumberInputElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "number_input", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let is_decimal_allowed = wire::field::<bool>(&mut map, "is_decimal_allowed", path)?;
let initial_value = wire::field::<String>(&mut map, "initial_value", path)?;
let min_value = wire::field::<f64>(&mut map, "min_value", path)?;
let max_value = wire::field::<f64>(&mut map, "max_value", path)?;
let dispatch_action_config =
wire::field::<DispatchActionConfiguration>(&mut map, "dispatch_action_config", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
NumberInputElementBuilder {
action_id,
is_decimal_allowed,
initial_value,
min_value,
max_value,
dispatch_action_config,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for NumberInputElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "NumberInputElement")
}
}
impl<'de> Deserialize<'de> for NumberInputElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct OverflowElement {
action_id: Option<String>,
options: Vec<SelectOption>,
confirm: Option<ConfirmationDialogue>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct OverflowElementBuilder {
action_id: Option<String>,
options: Option<Vec<SelectOption>>,
confirm: Option<ConfirmationDialogue>,
extensions: Map<String, Value>,
}
impl Default for OverflowElementBuilder {
fn default() -> Self {
Self {
action_id: None,
options: None,
confirm: None,
extensions: Map::new(),
}
}
}
impl OverflowElement {
pub fn builder() -> OverflowElementBuilder {
OverflowElementBuilder::default()
}
pub fn into_builder(self) -> OverflowElementBuilder {
OverflowElementBuilder {
action_id: self.action_id,
options: Some(self.options),
confirm: self.confirm,
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn options(&self) -> &[SelectOption] {
&self.options
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "overflow")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
map.serialize_entry("options", &self.options)?;
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl OverflowElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn options<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<SelectOption>,
{
self.options = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn option(mut self, value: impl Into<SelectOption>) -> Self {
self.options.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<OverflowElement, ValidationError> {
let action_id = self.action_id;
let options = wire::required(self.options, "OverflowElement.options")?;
let confirm = self.confirm;
wire::extensions(
&self.extensions,
&["action_id", "options", "confirm"],
"OverflowElement",
)?;
let value = OverflowElement {
action_id,
options,
confirm,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"OverflowElement.action_id",
)?;
}
{
let v = &value.options;
crate::rules::length(v.len(), Some(1), Some(5), "OverflowElement.options")?;
}
Ok(value)
}
}
impl Serialize for OverflowElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for OverflowElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "overflow", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let options = wire::field::<Vec<SelectOption>>(&mut map, "options", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
OverflowElementBuilder {
action_id,
options,
confirm,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for OverflowElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "OverflowElement")
}
}
impl<'de> Deserialize<'de> for OverflowElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct PlainTextInputElement {
action_id: Option<String>,
initial_value: Option<String>,
multiline: Option<bool>,
min_length: Option<i64>,
max_length: Option<i64>,
dispatch_action_config: Option<DispatchActionConfiguration>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct PlainTextInputElementBuilder {
action_id: Option<String>,
initial_value: Option<String>,
multiline: Option<bool>,
min_length: Option<i64>,
max_length: Option<i64>,
dispatch_action_config: Option<DispatchActionConfiguration>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for PlainTextInputElementBuilder {
fn default() -> Self {
Self {
action_id: None,
initial_value: None,
multiline: None,
min_length: None,
max_length: None,
dispatch_action_config: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl PlainTextInputElement {
pub fn builder() -> PlainTextInputElementBuilder {
PlainTextInputElementBuilder::default()
}
pub fn into_builder(self) -> PlainTextInputElementBuilder {
PlainTextInputElementBuilder {
action_id: self.action_id,
initial_value: self.initial_value,
multiline: self.multiline,
min_length: self.min_length,
max_length: self.max_length,
dispatch_action_config: self.dispatch_action_config,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn initial_value(&self) -> Option<&str> {
self.initial_value.as_deref()
}
pub fn multiline(&self) -> Option<bool> {
self.multiline
}
pub fn min_length(&self) -> Option<i64> {
self.min_length
}
pub fn max_length(&self) -> Option<i64> {
self.max_length
}
pub fn dispatch_action_config(&self) -> Option<&DispatchActionConfiguration> {
self.dispatch_action_config.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "plain_text_input")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.initial_value {
map.serialize_entry("initial_value", value)?;
}
if let Some(value) = &self.multiline {
map.serialize_entry("multiline", value)?;
}
if let Some(value) = &self.min_length {
map.serialize_entry("min_length", value)?;
}
if let Some(value) = &self.max_length {
map.serialize_entry("max_length", value)?;
}
if let Some(value) = &self.dispatch_action_config {
map.serialize_entry("dispatch_action_config", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl PlainTextInputElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn initial_value(mut self, value: impl Into<String>) -> Self {
self.initial_value = Some(value.into());
self
}
pub fn clear_initial_value(mut self) -> Self {
self.initial_value = None;
self
}
pub fn multiline(mut self, value: bool) -> Self {
self.multiline = Some(value);
self
}
pub fn clear_multiline(mut self) -> Self {
self.multiline = None;
self
}
pub fn min_length(mut self, value: i64) -> Self {
self.min_length = Some(value);
self
}
pub fn clear_min_length(mut self) -> Self {
self.min_length = None;
self
}
pub fn max_length(mut self, value: i64) -> Self {
self.max_length = Some(value);
self
}
pub fn clear_max_length(mut self) -> Self {
self.max_length = None;
self
}
pub fn dispatch_action_config(mut self, value: impl Into<DispatchActionConfiguration>) -> Self {
self.dispatch_action_config = Some(value.into());
self
}
pub fn clear_dispatch_action_config(mut self) -> Self {
self.dispatch_action_config = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<PlainTextInputElement, ValidationError> {
let action_id = self.action_id;
let initial_value = self.initial_value;
let multiline = self.multiline;
let min_length = self.min_length;
let max_length = self.max_length;
let dispatch_action_config = self.dispatch_action_config;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("PlainTextInputElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"initial_value",
"multiline",
"min_length",
"max_length",
"dispatch_action_config",
"focus_on_load",
"placeholder",
],
"PlainTextInputElement",
)?;
let value = PlainTextInputElement {
action_id,
initial_value,
multiline,
min_length,
max_length,
dispatch_action_config,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"PlainTextInputElement.action_id",
)?;
}
if let Some(v) = &value.min_length {
if *v < 0 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"PlainTextInputElement.min_length",
"number outside field bounds",
));
}
if *v > 3000 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"PlainTextInputElement.min_length",
"number outside field bounds",
));
}
}
if let Some(v) = &value.max_length {
if *v < 1 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"PlainTextInputElement.max_length",
"number outside field bounds",
));
}
if *v > 3000 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"PlainTextInputElement.max_length",
"number outside field bounds",
));
}
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"PlainTextInputElement.placeholder",
)?;
}
Ok(value)
}
}
impl Serialize for PlainTextInputElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for PlainTextInputElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "plain_text_input", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let initial_value = wire::field::<String>(&mut map, "initial_value", path)?;
let multiline = wire::field::<bool>(&mut map, "multiline", path)?;
let min_length = wire::field::<i64>(&mut map, "min_length", path)?;
let max_length = wire::field::<i64>(&mut map, "max_length", path)?;
let dispatch_action_config =
wire::field::<DispatchActionConfiguration>(&mut map, "dispatch_action_config", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
PlainTextInputElementBuilder {
action_id,
initial_value,
multiline,
min_length,
max_length,
dispatch_action_config,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for PlainTextInputElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "PlainTextInputElement")
}
}
impl<'de> Deserialize<'de> for PlainTextInputElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RadioButtonsElement {
action_id: Option<String>,
options: Vec<SelectOption>,
initial_option: Option<SelectOption>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RadioButtonsElementBuilder {
action_id: Option<String>,
options: Option<Vec<SelectOption>>,
initial_option: Option<SelectOption>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
extensions: Map<String, Value>,
}
impl Default for RadioButtonsElementBuilder {
fn default() -> Self {
Self {
action_id: None,
options: None,
initial_option: None,
confirm: None,
focus_on_load: None,
extensions: Map::new(),
}
}
}
impl RadioButtonsElement {
pub fn builder() -> RadioButtonsElementBuilder {
RadioButtonsElementBuilder::default()
}
pub fn into_builder(self) -> RadioButtonsElementBuilder {
RadioButtonsElementBuilder {
action_id: self.action_id,
options: Some(self.options),
initial_option: self.initial_option,
confirm: self.confirm,
focus_on_load: self.focus_on_load,
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn options(&self) -> &[SelectOption] {
&self.options
}
pub fn initial_option(&self) -> Option<&SelectOption> {
self.initial_option.as_ref()
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "radio_buttons")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
map.serialize_entry("options", &self.options)?;
if let Some(value) = &self.initial_option {
map.serialize_entry("initial_option", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RadioButtonsElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn options<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<SelectOption>,
{
self.options = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn option(mut self, value: impl Into<SelectOption>) -> Self {
self.options.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn initial_option(mut self, value: impl Into<SelectOption>) -> Self {
self.initial_option = Some(value.into());
self
}
pub fn clear_initial_option(mut self) -> Self {
self.initial_option = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RadioButtonsElement, ValidationError> {
let action_id = self.action_id;
let options = wire::required(self.options, "RadioButtonsElement.options")?;
let initial_option = self.initial_option;
let confirm = self.confirm;
let focus_on_load = self.focus_on_load;
wire::extensions(
&self.extensions,
&[
"action_id",
"options",
"initial_option",
"confirm",
"focus_on_load",
],
"RadioButtonsElement",
)?;
let value = RadioButtonsElement {
action_id,
options,
initial_option,
confirm,
focus_on_load,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"RadioButtonsElement.action_id",
)?;
}
{
let v = &value.options;
crate::rules::length(v.len(), Some(1), Some(10), "RadioButtonsElement.options")?;
}
Ok(value)
}
}
impl Serialize for RadioButtonsElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RadioButtonsElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "radio_buttons", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let options = wire::field::<Vec<SelectOption>>(&mut map, "options", path)?;
let initial_option = wire::field::<SelectOption>(&mut map, "initial_option", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
RadioButtonsElementBuilder {
action_id,
options,
initial_option,
confirm,
focus_on_load,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RadioButtonsElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RadioButtonsElement")
}
}
impl<'de> Deserialize<'de> for RadioButtonsElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RichTextInputElement {
action_id: String,
initial_value: Option<RichTextBlock>,
dispatch_action_config: Option<DispatchActionConfiguration>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
min_lines: Option<i64>,
max_lines: Option<i64>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RichTextInputElementBuilder {
action_id: Option<String>,
initial_value: Option<RichTextBlock>,
dispatch_action_config: Option<DispatchActionConfiguration>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
min_lines: Option<i64>,
max_lines: Option<i64>,
extensions: Map<String, Value>,
}
impl Default for RichTextInputElementBuilder {
fn default() -> Self {
Self {
action_id: None,
initial_value: None,
dispatch_action_config: None,
focus_on_load: None,
placeholder: None,
min_lines: None,
max_lines: None,
extensions: Map::new(),
}
}
}
impl RichTextInputElement {
pub fn builder() -> RichTextInputElementBuilder {
RichTextInputElementBuilder::default()
}
pub fn into_builder(self) -> RichTextInputElementBuilder {
RichTextInputElementBuilder {
action_id: Some(self.action_id),
initial_value: self.initial_value,
dispatch_action_config: self.dispatch_action_config,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
min_lines: self.min_lines,
max_lines: self.max_lines,
extensions: self.extensions,
}
}
pub fn action_id(&self) -> &str {
&self.action_id
}
pub fn initial_value(&self) -> Option<&RichTextBlock> {
self.initial_value.as_ref()
}
pub fn dispatch_action_config(&self) -> Option<&DispatchActionConfiguration> {
self.dispatch_action_config.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn min_lines(&self) -> Option<i64> {
self.min_lines
}
pub fn max_lines(&self) -> Option<i64> {
self.max_lines
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "rich_text_input")?;
map.serialize_entry("action_id", &self.action_id)?;
if let Some(value) = &self.initial_value {
map.serialize_entry("initial_value", value)?;
}
if let Some(value) = &self.dispatch_action_config {
map.serialize_entry("dispatch_action_config", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
if let Some(value) = &self.min_lines {
map.serialize_entry("min_lines", value)?;
}
if let Some(value) = &self.max_lines {
map.serialize_entry("max_lines", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RichTextInputElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn initial_value(mut self, value: impl Into<RichTextBlock>) -> Self {
self.initial_value = Some(value.into());
self
}
pub fn clear_initial_value(mut self) -> Self {
self.initial_value = None;
self
}
pub fn dispatch_action_config(mut self, value: impl Into<DispatchActionConfiguration>) -> Self {
self.dispatch_action_config = Some(value.into());
self
}
pub fn clear_dispatch_action_config(mut self) -> Self {
self.dispatch_action_config = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn min_lines(mut self, value: i64) -> Self {
self.min_lines = Some(value);
self
}
pub fn clear_min_lines(mut self) -> Self {
self.min_lines = None;
self
}
pub fn max_lines(mut self, value: i64) -> Self {
self.max_lines = Some(value);
self
}
pub fn clear_max_lines(mut self) -> Self {
self.max_lines = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RichTextInputElement, ValidationError> {
let action_id = wire::required(self.action_id, "RichTextInputElement.action_id")?;
let initial_value = self.initial_value;
let dispatch_action_config = self.dispatch_action_config;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("RichTextInputElement.placeholder"))
})
.transpose()?;
let min_lines = self.min_lines;
let max_lines = self.max_lines;
wire::extensions(
&self.extensions,
&[
"action_id",
"initial_value",
"dispatch_action_config",
"focus_on_load",
"placeholder",
"min_lines",
"max_lines",
],
"RichTextInputElement",
)?;
let value = RichTextInputElement {
action_id,
initial_value,
dispatch_action_config,
focus_on_load,
placeholder,
min_lines,
max_lines,
extensions: self.extensions,
};
{
let v = &value.action_id;
crate::rules::length(
v.chars().count(),
None,
Some(255),
"RichTextInputElement.action_id",
)?;
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"RichTextInputElement.placeholder",
)?;
}
if let Some(v) = &value.min_lines {
if *v < 1 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"RichTextInputElement.min_lines",
"number outside field bounds",
));
}
if *v > 100 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"RichTextInputElement.min_lines",
"number outside field bounds",
));
}
}
if let Some(v) = &value.max_lines {
if *v < 1 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"RichTextInputElement.max_lines",
"number outside field bounds",
));
}
if *v > 100 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"RichTextInputElement.max_lines",
"number outside field bounds",
));
}
}
Ok(value)
}
}
impl Serialize for RichTextInputElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RichTextInputElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "rich_text_input", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let initial_value = wire::field::<RichTextBlock>(&mut map, "initial_value", path)?;
let dispatch_action_config =
wire::field::<DispatchActionConfiguration>(&mut map, "dispatch_action_config", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
let min_lines = wire::field::<i64>(&mut map, "min_lines", path)?;
let max_lines = wire::field::<i64>(&mut map, "max_lines", path)?;
RichTextInputElementBuilder {
action_id,
initial_value,
dispatch_action_config,
focus_on_load,
placeholder: placeholder.map(Into::into),
min_lines,
max_lines,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RichTextInputElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextInputElement")
}
}
impl<'de> Deserialize<'de> for RichTextInputElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct StaticMultiSelectElement {
action_id: Option<String>,
options: Option<Vec<SelectOption>>,
option_groups: Option<Vec<SelectOptionGroup>>,
initial_options: Option<Vec<SelectOption>>,
confirm: Option<ConfirmationDialogue>,
max_selected_items: Option<i64>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct StaticMultiSelectElementBuilder {
action_id: Option<String>,
options: Option<Vec<SelectOption>>,
option_groups: Option<Vec<SelectOptionGroup>>,
initial_options: Option<Vec<SelectOption>>,
confirm: Option<ConfirmationDialogue>,
max_selected_items: Option<i64>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for StaticMultiSelectElementBuilder {
fn default() -> Self {
Self {
action_id: None,
options: None,
option_groups: None,
initial_options: None,
confirm: None,
max_selected_items: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl StaticMultiSelectElement {
pub fn builder() -> StaticMultiSelectElementBuilder {
StaticMultiSelectElementBuilder::default()
}
pub fn into_builder(self) -> StaticMultiSelectElementBuilder {
StaticMultiSelectElementBuilder {
action_id: self.action_id,
options: self.options,
option_groups: self.option_groups,
initial_options: self.initial_options,
confirm: self.confirm,
max_selected_items: self.max_selected_items,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn options(&self) -> Option<&[SelectOption]> {
self.options.as_deref()
}
pub fn option_groups(&self) -> Option<&[SelectOptionGroup]> {
self.option_groups.as_deref()
}
pub fn initial_options(&self) -> Option<&[SelectOption]> {
self.initial_options.as_deref()
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn max_selected_items(&self) -> Option<i64> {
self.max_selected_items
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "multi_static_select")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.options {
map.serialize_entry("options", value)?;
}
if let Some(value) = &self.option_groups {
map.serialize_entry("option_groups", value)?;
}
if let Some(value) = &self.initial_options {
map.serialize_entry("initial_options", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.max_selected_items {
map.serialize_entry("max_selected_items", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl StaticMultiSelectElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn options<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<SelectOption>,
{
self.options = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn option(mut self, value: impl Into<SelectOption>) -> Self {
self.options.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn clear_options(mut self) -> Self {
self.options = None;
self
}
pub fn option_groups<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<SelectOptionGroup>,
{
self.option_groups = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn option_group(mut self, value: impl Into<SelectOptionGroup>) -> Self {
self.option_groups
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_option_groups(mut self) -> Self {
self.option_groups = None;
self
}
pub fn initial_options<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<SelectOption>,
{
self.initial_options = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn initial_option(mut self, value: impl Into<SelectOption>) -> Self {
self.initial_options
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_initial_options(mut self) -> Self {
self.initial_options = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn max_selected_items(mut self, value: i64) -> Self {
self.max_selected_items = Some(value);
self
}
pub fn clear_max_selected_items(mut self) -> Self {
self.max_selected_items = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<StaticMultiSelectElement, ValidationError> {
let action_id = self.action_id;
let options = self.options;
let option_groups = self.option_groups;
let initial_options = self.initial_options;
let confirm = self.confirm;
let max_selected_items = self.max_selected_items;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("StaticMultiSelectElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"options",
"option_groups",
"initial_options",
"confirm",
"max_selected_items",
"focus_on_load",
"placeholder",
],
"StaticMultiSelectElement",
)?;
let value = StaticMultiSelectElement {
action_id,
options,
option_groups,
initial_options,
confirm,
max_selected_items,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"StaticMultiSelectElement.action_id",
)?;
}
if let Some(v) = &value.options {
crate::rules::length(v.len(), None, Some(100), "StaticMultiSelectElement.options")?;
}
if let Some(v) = &value.option_groups {
crate::rules::length(
v.len(),
None,
Some(100),
"StaticMultiSelectElement.option_groups",
)?;
}
if let Some(v) = &value.max_selected_items {
if *v < 1 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"StaticMultiSelectElement.max_selected_items",
"number outside field bounds",
));
}
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"StaticMultiSelectElement.placeholder",
)?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(
ErrorCategory::TypeMismatch,
"StaticMultiSelectElement",
e.to_string(),
)
})?;
crate::rules::validate(
"StaticMultiSelectElement",
&wire,
"StaticMultiSelectElement",
)?;
Ok(value)
}
}
impl Serialize for StaticMultiSelectElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for StaticMultiSelectElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "multi_static_select", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let options = wire::field::<Vec<SelectOption>>(&mut map, "options", path)?;
let option_groups = wire::field::<Vec<SelectOptionGroup>>(&mut map, "option_groups", path)?;
let initial_options = wire::field::<Vec<SelectOption>>(&mut map, "initial_options", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let max_selected_items = wire::field::<i64>(&mut map, "max_selected_items", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
StaticMultiSelectElementBuilder {
action_id,
options,
option_groups,
initial_options,
confirm,
max_selected_items,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for StaticMultiSelectElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "StaticMultiSelectElement")
}
}
impl<'de> Deserialize<'de> for StaticMultiSelectElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct StaticSelectElement {
action_id: Option<String>,
options: Option<Vec<SelectOption>>,
option_groups: Option<Vec<SelectOptionGroup>>,
initial_option: Option<SelectOption>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct StaticSelectElementBuilder {
action_id: Option<String>,
options: Option<Vec<SelectOption>>,
option_groups: Option<Vec<SelectOptionGroup>>,
initial_option: Option<SelectOption>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for StaticSelectElementBuilder {
fn default() -> Self {
Self {
action_id: None,
options: None,
option_groups: None,
initial_option: None,
confirm: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl StaticSelectElement {
pub fn builder() -> StaticSelectElementBuilder {
StaticSelectElementBuilder::default()
}
pub fn into_builder(self) -> StaticSelectElementBuilder {
StaticSelectElementBuilder {
action_id: self.action_id,
options: self.options,
option_groups: self.option_groups,
initial_option: self.initial_option,
confirm: self.confirm,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn options(&self) -> Option<&[SelectOption]> {
self.options.as_deref()
}
pub fn option_groups(&self) -> Option<&[SelectOptionGroup]> {
self.option_groups.as_deref()
}
pub fn initial_option(&self) -> Option<&SelectOption> {
self.initial_option.as_ref()
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "static_select")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.options {
map.serialize_entry("options", value)?;
}
if let Some(value) = &self.option_groups {
map.serialize_entry("option_groups", value)?;
}
if let Some(value) = &self.initial_option {
map.serialize_entry("initial_option", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl StaticSelectElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn options<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<SelectOption>,
{
self.options = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn option(mut self, value: impl Into<SelectOption>) -> Self {
self.options.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn clear_options(mut self) -> Self {
self.options = None;
self
}
pub fn option_groups<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<SelectOptionGroup>,
{
self.option_groups = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn option_group(mut self, value: impl Into<SelectOptionGroup>) -> Self {
self.option_groups
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_option_groups(mut self) -> Self {
self.option_groups = None;
self
}
pub fn initial_option(mut self, value: impl Into<SelectOption>) -> Self {
self.initial_option = Some(value.into());
self
}
pub fn clear_initial_option(mut self) -> Self {
self.initial_option = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<StaticSelectElement, ValidationError> {
let action_id = self.action_id;
let options = self.options;
let option_groups = self.option_groups;
let initial_option = self.initial_option;
let confirm = self.confirm;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("StaticSelectElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"options",
"option_groups",
"initial_option",
"confirm",
"focus_on_load",
"placeholder",
],
"StaticSelectElement",
)?;
let value = StaticSelectElement {
action_id,
options,
option_groups,
initial_option,
confirm,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"StaticSelectElement.action_id",
)?;
}
if let Some(v) = &value.options {
crate::rules::length(v.len(), None, Some(100), "StaticSelectElement.options")?;
}
if let Some(v) = &value.option_groups {
crate::rules::length(
v.len(),
None,
Some(100),
"StaticSelectElement.option_groups",
)?;
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"StaticSelectElement.placeholder",
)?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(
ErrorCategory::TypeMismatch,
"StaticSelectElement",
e.to_string(),
)
})?;
crate::rules::validate("StaticSelectElement", &wire, "StaticSelectElement")?;
Ok(value)
}
}
impl Serialize for StaticSelectElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for StaticSelectElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "static_select", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let options = wire::field::<Vec<SelectOption>>(&mut map, "options", path)?;
let option_groups = wire::field::<Vec<SelectOptionGroup>>(&mut map, "option_groups", path)?;
let initial_option = wire::field::<SelectOption>(&mut map, "initial_option", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
StaticSelectElementBuilder {
action_id,
options,
option_groups,
initial_option,
confirm,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for StaticSelectElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "StaticSelectElement")
}
}
impl<'de> Deserialize<'de> for StaticSelectElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct TimePickerElement {
action_id: Option<String>,
initial_time: Option<String>,
timezone: Option<String>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct TimePickerElementBuilder {
action_id: Option<String>,
initial_time: Option<String>,
timezone: Option<String>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for TimePickerElementBuilder {
fn default() -> Self {
Self {
action_id: None,
initial_time: None,
timezone: None,
confirm: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl TimePickerElement {
pub fn builder() -> TimePickerElementBuilder {
TimePickerElementBuilder::default()
}
pub fn into_builder(self) -> TimePickerElementBuilder {
TimePickerElementBuilder {
action_id: self.action_id,
initial_time: self.initial_time,
timezone: self.timezone,
confirm: self.confirm,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn initial_time(&self) -> Option<&str> {
self.initial_time.as_deref()
}
pub fn timezone(&self) -> Option<&str> {
self.timezone.as_deref()
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "timepicker")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.initial_time {
map.serialize_entry("initial_time", value)?;
}
if let Some(value) = &self.timezone {
map.serialize_entry("timezone", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl TimePickerElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn initial_time(mut self, value: impl Into<String>) -> Self {
self.initial_time = Some(value.into());
self
}
pub fn clear_initial_time(mut self) -> Self {
self.initial_time = None;
self
}
pub fn timezone(mut self, value: impl Into<String>) -> Self {
self.timezone = Some(value.into());
self
}
pub fn clear_timezone(mut self) -> Self {
self.timezone = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<TimePickerElement, ValidationError> {
let action_id = self.action_id;
let initial_time = self.initial_time;
let timezone = self.timezone;
let confirm = self.confirm;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("TimePickerElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"initial_time",
"timezone",
"confirm",
"focus_on_load",
"placeholder",
],
"TimePickerElement",
)?;
let value = TimePickerElement {
action_id,
initial_time,
timezone,
confirm,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"TimePickerElement.action_id",
)?;
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"TimePickerElement.placeholder",
)?;
}
Ok(value)
}
}
impl Serialize for TimePickerElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for TimePickerElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "timepicker", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let initial_time = wire::field::<String>(&mut map, "initial_time", path)?;
let timezone = wire::field::<String>(&mut map, "timezone", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
TimePickerElementBuilder {
action_id,
initial_time,
timezone,
confirm,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for TimePickerElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "TimePickerElement")
}
}
impl<'de> Deserialize<'de> for TimePickerElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct UrlInputElement {
action_id: Option<String>,
initial_value: Option<String>,
dispatch_action_config: Option<DispatchActionConfiguration>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct UrlInputElementBuilder {
action_id: Option<String>,
initial_value: Option<String>,
dispatch_action_config: Option<DispatchActionConfiguration>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for UrlInputElementBuilder {
fn default() -> Self {
Self {
action_id: None,
initial_value: None,
dispatch_action_config: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl UrlInputElement {
pub fn builder() -> UrlInputElementBuilder {
UrlInputElementBuilder::default()
}
pub fn into_builder(self) -> UrlInputElementBuilder {
UrlInputElementBuilder {
action_id: self.action_id,
initial_value: self.initial_value,
dispatch_action_config: self.dispatch_action_config,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn initial_value(&self) -> Option<&str> {
self.initial_value.as_deref()
}
pub fn dispatch_action_config(&self) -> Option<&DispatchActionConfiguration> {
self.dispatch_action_config.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "url_text_input")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.initial_value {
map.serialize_entry("initial_value", value)?;
}
if let Some(value) = &self.dispatch_action_config {
map.serialize_entry("dispatch_action_config", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl UrlInputElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn initial_value(mut self, value: impl Into<String>) -> Self {
self.initial_value = Some(value.into());
self
}
pub fn clear_initial_value(mut self) -> Self {
self.initial_value = None;
self
}
pub fn dispatch_action_config(mut self, value: impl Into<DispatchActionConfiguration>) -> Self {
self.dispatch_action_config = Some(value.into());
self
}
pub fn clear_dispatch_action_config(mut self) -> Self {
self.dispatch_action_config = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<UrlInputElement, ValidationError> {
let action_id = self.action_id;
let initial_value = self.initial_value;
let dispatch_action_config = self.dispatch_action_config;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| v.resolve().map_err(|e| e.at("UrlInputElement.placeholder")))
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"initial_value",
"dispatch_action_config",
"focus_on_load",
"placeholder",
],
"UrlInputElement",
)?;
let value = UrlInputElement {
action_id,
initial_value,
dispatch_action_config,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"UrlInputElement.action_id",
)?;
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"UrlInputElement.placeholder",
)?;
}
Ok(value)
}
}
impl Serialize for UrlInputElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for UrlInputElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "url_text_input", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let initial_value = wire::field::<String>(&mut map, "initial_value", path)?;
let dispatch_action_config =
wire::field::<DispatchActionConfiguration>(&mut map, "dispatch_action_config", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
UrlInputElementBuilder {
action_id,
initial_value,
dispatch_action_config,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for UrlInputElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "UrlInputElement")
}
}
impl<'de> Deserialize<'de> for UrlInputElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct UserMultiSelectElement {
action_id: Option<String>,
initial_users: Option<Vec<String>>,
confirm: Option<ConfirmationDialogue>,
max_selected_items: Option<i64>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct UserMultiSelectElementBuilder {
action_id: Option<String>,
initial_users: Option<Vec<String>>,
confirm: Option<ConfirmationDialogue>,
max_selected_items: Option<i64>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for UserMultiSelectElementBuilder {
fn default() -> Self {
Self {
action_id: None,
initial_users: None,
confirm: None,
max_selected_items: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl UserMultiSelectElement {
pub fn builder() -> UserMultiSelectElementBuilder {
UserMultiSelectElementBuilder::default()
}
pub fn into_builder(self) -> UserMultiSelectElementBuilder {
UserMultiSelectElementBuilder {
action_id: self.action_id,
initial_users: self.initial_users,
confirm: self.confirm,
max_selected_items: self.max_selected_items,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn initial_users(&self) -> Option<&[String]> {
self.initial_users.as_deref()
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn max_selected_items(&self) -> Option<i64> {
self.max_selected_items
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "multi_users_select")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.initial_users {
map.serialize_entry("initial_users", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.max_selected_items {
map.serialize_entry("max_selected_items", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl UserMultiSelectElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn initial_users<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<String>,
{
self.initial_users = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn initial_user(mut self, value: impl Into<String>) -> Self {
self.initial_users
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_initial_users(mut self) -> Self {
self.initial_users = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn max_selected_items(mut self, value: i64) -> Self {
self.max_selected_items = Some(value);
self
}
pub fn clear_max_selected_items(mut self) -> Self {
self.max_selected_items = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<UserMultiSelectElement, ValidationError> {
let action_id = self.action_id;
let initial_users = self.initial_users;
let confirm = self.confirm;
let max_selected_items = self.max_selected_items;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("UserMultiSelectElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"initial_users",
"confirm",
"max_selected_items",
"focus_on_load",
"placeholder",
],
"UserMultiSelectElement",
)?;
let value = UserMultiSelectElement {
action_id,
initial_users,
confirm,
max_selected_items,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"UserMultiSelectElement.action_id",
)?;
}
if let Some(v) = &value.max_selected_items {
if *v < 1 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"UserMultiSelectElement.max_selected_items",
"number outside field bounds",
));
}
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"UserMultiSelectElement.placeholder",
)?;
}
Ok(value)
}
}
impl Serialize for UserMultiSelectElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for UserMultiSelectElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "multi_users_select", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let initial_users = wire::field::<Vec<String>>(&mut map, "initial_users", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let max_selected_items = wire::field::<i64>(&mut map, "max_selected_items", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
UserMultiSelectElementBuilder {
action_id,
initial_users,
confirm,
max_selected_items,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for UserMultiSelectElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "UserMultiSelectElement")
}
}
impl<'de> Deserialize<'de> for UserMultiSelectElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct UserSelectElement {
action_id: Option<String>,
initial_user: Option<String>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainText>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct UserSelectElementBuilder {
action_id: Option<String>,
initial_user: Option<String>,
confirm: Option<ConfirmationDialogue>,
focus_on_load: Option<bool>,
placeholder: Option<PlainTextInput>,
extensions: Map<String, Value>,
}
impl Default for UserSelectElementBuilder {
fn default() -> Self {
Self {
action_id: None,
initial_user: None,
confirm: None,
focus_on_load: None,
placeholder: None,
extensions: Map::new(),
}
}
}
impl UserSelectElement {
pub fn builder() -> UserSelectElementBuilder {
UserSelectElementBuilder::default()
}
pub fn into_builder(self) -> UserSelectElementBuilder {
UserSelectElementBuilder {
action_id: self.action_id,
initial_user: self.initial_user,
confirm: self.confirm,
focus_on_load: self.focus_on_load,
placeholder: self.placeholder.map(Into::into),
extensions: self.extensions,
}
}
pub fn action_id(&self) -> Option<&str> {
self.action_id.as_deref()
}
pub fn initial_user(&self) -> Option<&str> {
self.initial_user.as_deref()
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn focus_on_load(&self) -> Option<bool> {
self.focus_on_load
}
pub fn placeholder(&self) -> Option<&PlainText> {
self.placeholder.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "users_select")?;
if let Some(value) = &self.action_id {
map.serialize_entry("action_id", value)?;
}
if let Some(value) = &self.initial_user {
map.serialize_entry("initial_user", value)?;
}
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.focus_on_load {
map.serialize_entry("focus_on_load", value)?;
}
if let Some(value) = &self.placeholder {
map.serialize_entry("placeholder", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl UserSelectElementBuilder {
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn clear_action_id(mut self) -> Self {
self.action_id = None;
self
}
pub fn initial_user(mut self, value: impl Into<String>) -> Self {
self.initial_user = Some(value.into());
self
}
pub fn clear_initial_user(mut self) -> Self {
self.initial_user = None;
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn focus_on_load(mut self, value: bool) -> Self {
self.focus_on_load = Some(value);
self
}
pub fn clear_focus_on_load(mut self) -> Self {
self.focus_on_load = None;
self
}
pub fn placeholder(mut self, value: impl Into<PlainTextInput>) -> Self {
self.placeholder = Some(value.into());
self
}
pub fn clear_placeholder(mut self) -> Self {
self.placeholder = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<UserSelectElement, ValidationError> {
let action_id = self.action_id;
let initial_user = self.initial_user;
let confirm = self.confirm;
let focus_on_load = self.focus_on_load;
let placeholder = self
.placeholder
.map(|v| {
v.resolve()
.map_err(|e| e.at("UserSelectElement.placeholder"))
})
.transpose()?;
wire::extensions(
&self.extensions,
&[
"action_id",
"initial_user",
"confirm",
"focus_on_load",
"placeholder",
],
"UserSelectElement",
)?;
let value = UserSelectElement {
action_id,
initial_user,
confirm,
focus_on_load,
placeholder,
extensions: self.extensions,
};
if let Some(v) = &value.action_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"UserSelectElement.action_id",
)?;
}
if let Some(v) = &value.placeholder {
crate::rules::length(
v.text().chars().count(),
None,
Some(150),
"UserSelectElement.placeholder",
)?;
}
Ok(value)
}
}
impl Serialize for UserSelectElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for UserSelectElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "users_select", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let initial_user = wire::field::<String>(&mut map, "initial_user", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let focus_on_load = wire::field::<bool>(&mut map, "focus_on_load", path)?;
crate::rules::coerce_text(map.get_mut("placeholder"), "plain_text");
let placeholder = wire::field::<PlainText>(&mut map, "placeholder", path)?;
UserSelectElementBuilder {
action_id,
initial_user,
confirm,
focus_on_load,
placeholder: placeholder.map(Into::into),
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for UserSelectElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "UserSelectElement")
}
}
impl<'de> Deserialize<'de> for UserSelectElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct WorkflowButtonElement {
text: PlainText,
workflow: Workflow,
action_id: String,
confirm: Option<ConfirmationDialogue>,
style: Option<ButtonStyle>,
accessibility_label: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct WorkflowButtonElementBuilder {
text: Option<PlainTextInput>,
workflow: Option<Workflow>,
action_id: Option<String>,
confirm: Option<ConfirmationDialogue>,
style: Option<ButtonStyle>,
accessibility_label: Option<String>,
extensions: Map<String, Value>,
}
impl Default for WorkflowButtonElementBuilder {
fn default() -> Self {
Self {
text: None,
workflow: None,
action_id: None,
confirm: None,
style: None,
accessibility_label: None,
extensions: Map::new(),
}
}
}
impl WorkflowButtonElement {
pub fn builder() -> WorkflowButtonElementBuilder {
WorkflowButtonElementBuilder::default()
}
pub fn into_builder(self) -> WorkflowButtonElementBuilder {
WorkflowButtonElementBuilder {
text: Some(self.text.into()),
workflow: Some(self.workflow),
action_id: Some(self.action_id),
confirm: self.confirm,
style: self.style,
accessibility_label: self.accessibility_label,
extensions: self.extensions,
}
}
pub fn text(&self) -> &PlainText {
&self.text
}
pub fn workflow(&self) -> &Workflow {
&self.workflow
}
pub fn action_id(&self) -> &str {
&self.action_id
}
pub fn confirm(&self) -> Option<&ConfirmationDialogue> {
self.confirm.as_ref()
}
pub fn style(&self) -> Option<ButtonStyle> {
self.style
}
pub fn accessibility_label(&self) -> Option<&str> {
self.accessibility_label.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "workflow_button")?;
map.serialize_entry("text", &self.text)?;
map.serialize_entry("workflow", &self.workflow)?;
map.serialize_entry("action_id", &self.action_id)?;
if let Some(value) = &self.confirm {
map.serialize_entry("confirm", value)?;
}
if let Some(value) = &self.style {
map.serialize_entry("style", value)?;
}
if let Some(value) = &self.accessibility_label {
map.serialize_entry("accessibility_label", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl WorkflowButtonElementBuilder {
pub fn text(mut self, value: impl Into<PlainTextInput>) -> Self {
self.text = Some(value.into());
self
}
pub fn workflow(mut self, value: impl Into<Workflow>) -> Self {
self.workflow = Some(value.into());
self
}
pub fn action_id(mut self, value: impl Into<String>) -> Self {
self.action_id = Some(value.into());
self
}
pub fn confirm(mut self, value: impl Into<ConfirmationDialogue>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn clear_confirm(mut self) -> Self {
self.confirm = None;
self
}
pub fn style(mut self, value: ButtonStyle) -> Self {
self.style = Some(value);
self
}
pub fn clear_style(mut self) -> Self {
self.style = None;
self
}
pub fn accessibility_label(mut self, value: impl Into<String>) -> Self {
self.accessibility_label = Some(value.into());
self
}
pub fn clear_accessibility_label(mut self) -> Self {
self.accessibility_label = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<WorkflowButtonElement, ValidationError> {
let text = wire::required(
self.text
.map(|v| v.resolve().map_err(|e| e.at("WorkflowButtonElement.text")))
.transpose()?,
"WorkflowButtonElement.text",
)?;
let workflow = wire::required(self.workflow, "WorkflowButtonElement.workflow")?;
let action_id = wire::required(self.action_id, "WorkflowButtonElement.action_id")?;
let confirm = self.confirm;
let style = self.style;
let accessibility_label = self.accessibility_label;
wire::extensions(
&self.extensions,
&[
"text",
"workflow",
"action_id",
"confirm",
"style",
"accessibility_label",
],
"WorkflowButtonElement",
)?;
let value = WorkflowButtonElement {
text,
workflow,
action_id,
confirm,
style,
accessibility_label,
extensions: self.extensions,
};
{
let v = &value.text;
crate::rules::length(
v.text().chars().count(),
None,
Some(75),
"WorkflowButtonElement.text",
)?;
}
{
let v = &value.action_id;
crate::rules::length(
v.chars().count(),
None,
Some(255),
"WorkflowButtonElement.action_id",
)?;
}
if let Some(v) = &value.accessibility_label {
crate::rules::length(
v.chars().count(),
None,
Some(75),
"WorkflowButtonElement.accessibility_label",
)?;
}
Ok(value)
}
}
impl Serialize for WorkflowButtonElement {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for WorkflowButtonElement {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "workflow_button", path)?;
crate::rules::coerce_text(map.get_mut("text"), "plain_text");
let text = wire::field::<PlainText>(&mut map, "text", path)?;
let workflow = wire::field::<Workflow>(&mut map, "workflow", path)?;
let action_id = wire::field::<String>(&mut map, "action_id", path)?;
let confirm = wire::field::<ConfirmationDialogue>(&mut map, "confirm", path)?;
let style = wire::field::<ButtonStyle>(&mut map, "style", path)?;
let accessibility_label = wire::field::<String>(&mut map, "accessibility_label", path)?;
WorkflowButtonElementBuilder {
text: text.map(Into::into),
workflow,
action_id,
confirm,
style,
accessibility_label,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for WorkflowButtonElement {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "WorkflowButtonElement")
}
}
impl<'de> Deserialize<'de> for WorkflowButtonElement {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct AreaChart {
series: Vec<DataSeries>,
axis_config: AxisConfig,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct AreaChartBuilder {
series: Option<Vec<DataSeries>>,
axis_config: Option<AxisConfig>,
extensions: Map<String, Value>,
}
impl Default for AreaChartBuilder {
fn default() -> Self {
Self {
series: None,
axis_config: None,
extensions: Map::new(),
}
}
}
impl AreaChart {
pub fn builder() -> AreaChartBuilder {
AreaChartBuilder::default()
}
pub fn into_builder(self) -> AreaChartBuilder {
AreaChartBuilder {
series: Some(self.series),
axis_config: Some(self.axis_config),
extensions: self.extensions,
}
}
pub fn series(&self) -> &[DataSeries] {
&self.series
}
pub fn axis_config(&self) -> &AxisConfig {
&self.axis_config
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "area")?;
map.serialize_entry("series", &self.series)?;
map.serialize_entry("axis_config", &self.axis_config)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl AreaChartBuilder {
pub fn series<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<DataSeries>,
{
self.series = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn series_entry(mut self, value: impl Into<DataSeries>) -> Self {
self.series.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn axis_config(mut self, value: impl Into<AxisConfig>) -> Self {
self.axis_config = Some(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<AreaChart, ValidationError> {
let series = wire::required(self.series, "AreaChart.series")?;
let axis_config = wire::required(self.axis_config, "AreaChart.axis_config")?;
wire::extensions(&self.extensions, &["series", "axis_config"], "AreaChart")?;
let value = AreaChart {
series,
axis_config,
extensions: self.extensions,
};
{
let v = &value.series;
crate::rules::length(v.len(), Some(1), Some(12), "AreaChart.series")?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "AreaChart", e.to_string())
})?;
crate::rules::validate("AreaChart", &wire, "AreaChart")?;
Ok(value)
}
}
impl Serialize for AreaChart {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for AreaChart {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "area", path)?;
let series = wire::field::<Vec<DataSeries>>(&mut map, "series", path)?;
let axis_config = wire::field::<AxisConfig>(&mut map, "axis_config", path)?;
AreaChartBuilder {
series,
axis_config,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for AreaChart {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "AreaChart")
}
}
impl<'de> Deserialize<'de> for AreaChart {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct AxisConfig {
categories: Vec<String>,
x_label: Option<String>,
y_label: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct AxisConfigBuilder {
categories: Option<Vec<String>>,
x_label: Option<String>,
y_label: Option<String>,
extensions: Map<String, Value>,
}
impl Default for AxisConfigBuilder {
fn default() -> Self {
Self {
categories: None,
x_label: None,
y_label: None,
extensions: Map::new(),
}
}
}
impl AxisConfig {
pub fn builder() -> AxisConfigBuilder {
AxisConfigBuilder::default()
}
pub fn into_builder(self) -> AxisConfigBuilder {
AxisConfigBuilder {
categories: Some(self.categories),
x_label: self.x_label,
y_label: self.y_label,
extensions: self.extensions,
}
}
pub fn categories(&self) -> &[String] {
&self.categories
}
pub fn x_label(&self) -> Option<&str> {
self.x_label.as_deref()
}
pub fn y_label(&self) -> Option<&str> {
self.y_label.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("categories", &self.categories)?;
if let Some(value) = &self.x_label {
map.serialize_entry("x_label", value)?;
}
if let Some(value) = &self.y_label {
map.serialize_entry("y_label", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl AxisConfigBuilder {
pub fn categories<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<String>,
{
self.categories = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn category(mut self, value: impl Into<String>) -> Self {
self.categories
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn x_label(mut self, value: impl Into<String>) -> Self {
self.x_label = Some(value.into());
self
}
pub fn clear_x_label(mut self) -> Self {
self.x_label = None;
self
}
pub fn y_label(mut self, value: impl Into<String>) -> Self {
self.y_label = Some(value.into());
self
}
pub fn clear_y_label(mut self) -> Self {
self.y_label = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<AxisConfig, ValidationError> {
let categories = wire::required(self.categories, "AxisConfig.categories")?;
let x_label = self.x_label;
let y_label = self.y_label;
wire::extensions(
&self.extensions,
&["categories", "x_label", "y_label"],
"AxisConfig",
)?;
let value = AxisConfig {
categories,
x_label,
y_label,
extensions: self.extensions,
};
{
let v = &value.categories;
crate::rules::length(v.len(), Some(1), Some(20), "AxisConfig.categories")?;
}
if let Some(v) = &value.x_label {
crate::rules::length(v.chars().count(), None, Some(50), "AxisConfig.x_label")?;
}
if let Some(v) = &value.y_label {
crate::rules::length(v.chars().count(), None, Some(50), "AxisConfig.y_label")?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "AxisConfig", e.to_string())
})?;
crate::rules::validate("AxisConfig", &wire, "AxisConfig")?;
Ok(value)
}
}
impl Serialize for AxisConfig {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for AxisConfig {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let categories = wire::field::<Vec<String>>(&mut map, "categories", path)?;
let x_label = wire::field::<String>(&mut map, "x_label", path)?;
let y_label = wire::field::<String>(&mut map, "y_label", path)?;
AxisConfigBuilder {
categories,
x_label,
y_label,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for AxisConfig {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "AxisConfig")
}
}
impl<'de> Deserialize<'de> for AxisConfig {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct BarChart {
series: Vec<DataSeries>,
axis_config: AxisConfig,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct BarChartBuilder {
series: Option<Vec<DataSeries>>,
axis_config: Option<AxisConfig>,
extensions: Map<String, Value>,
}
impl Default for BarChartBuilder {
fn default() -> Self {
Self {
series: None,
axis_config: None,
extensions: Map::new(),
}
}
}
impl BarChart {
pub fn builder() -> BarChartBuilder {
BarChartBuilder::default()
}
pub fn into_builder(self) -> BarChartBuilder {
BarChartBuilder {
series: Some(self.series),
axis_config: Some(self.axis_config),
extensions: self.extensions,
}
}
pub fn series(&self) -> &[DataSeries] {
&self.series
}
pub fn axis_config(&self) -> &AxisConfig {
&self.axis_config
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "bar")?;
map.serialize_entry("series", &self.series)?;
map.serialize_entry("axis_config", &self.axis_config)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl BarChartBuilder {
pub fn series<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<DataSeries>,
{
self.series = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn series_entry(mut self, value: impl Into<DataSeries>) -> Self {
self.series.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn axis_config(mut self, value: impl Into<AxisConfig>) -> Self {
self.axis_config = Some(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<BarChart, ValidationError> {
let series = wire::required(self.series, "BarChart.series")?;
let axis_config = wire::required(self.axis_config, "BarChart.axis_config")?;
wire::extensions(&self.extensions, &["series", "axis_config"], "BarChart")?;
let value = BarChart {
series,
axis_config,
extensions: self.extensions,
};
{
let v = &value.series;
crate::rules::length(v.len(), Some(1), Some(12), "BarChart.series")?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "BarChart", e.to_string())
})?;
crate::rules::validate("BarChart", &wire, "BarChart")?;
Ok(value)
}
}
impl Serialize for BarChart {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for BarChart {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "bar", path)?;
let series = wire::field::<Vec<DataSeries>>(&mut map, "series", path)?;
let axis_config = wire::field::<AxisConfig>(&mut map, "axis_config", path)?;
BarChartBuilder {
series,
axis_config,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for BarChart {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "BarChart")
}
}
impl<'de> Deserialize<'de> for BarChart {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ChartSegment {
label: String,
value: JsonNumber,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ChartSegmentBuilder {
label: Option<String>,
value: Option<JsonNumber>,
extensions: Map<String, Value>,
}
impl Default for ChartSegmentBuilder {
fn default() -> Self {
Self {
label: None,
value: None,
extensions: Map::new(),
}
}
}
impl ChartSegment {
pub fn builder() -> ChartSegmentBuilder {
ChartSegmentBuilder::default()
}
pub fn into_builder(self) -> ChartSegmentBuilder {
ChartSegmentBuilder {
label: Some(self.label),
value: Some(self.value),
extensions: self.extensions,
}
}
pub fn label(&self) -> &str {
&self.label
}
pub fn value(&self) -> &JsonNumber {
&self.value
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("label", &self.label)?;
map.serialize_entry("value", &self.value)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ChartSegmentBuilder {
pub fn label(mut self, value: impl Into<String>) -> Self {
self.label = Some(value.into());
self
}
pub fn value(mut self, value: impl Into<JsonNumber>) -> Self {
self.value = Some(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ChartSegment, ValidationError> {
let label = wire::required(self.label, "ChartSegment.label")?;
let value = wire::required(self.value, "ChartSegment.value")?;
wire::extensions(&self.extensions, &["label", "value"], "ChartSegment")?;
let value = ChartSegment {
label,
value,
extensions: self.extensions,
};
{
let v = &value.label;
crate::rules::length(v.chars().count(), None, Some(20), "ChartSegment.label")?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "ChartSegment", e.to_string())
})?;
crate::rules::validate("ChartSegment", &wire, "ChartSegment")?;
Ok(value)
}
}
impl Serialize for ChartSegment {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ChartSegment {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let label = wire::field::<String>(&mut map, "label", path)?;
let value = wire::field::<JsonNumber>(&mut map, "value", path)?;
ChartSegmentBuilder {
label,
value,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ChartSegment {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ChartSegment")
}
}
impl<'de> Deserialize<'de> for ChartSegment {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ColumnSettings {
align: Option<ColumnAlign>,
is_wrapped: Option<bool>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ColumnSettingsBuilder {
align: Option<ColumnAlign>,
is_wrapped: Option<bool>,
extensions: Map<String, Value>,
}
impl Default for ColumnSettingsBuilder {
fn default() -> Self {
Self {
align: None,
is_wrapped: None,
extensions: Map::new(),
}
}
}
impl ColumnSettings {
pub fn builder() -> ColumnSettingsBuilder {
ColumnSettingsBuilder::default()
}
pub fn into_builder(self) -> ColumnSettingsBuilder {
ColumnSettingsBuilder {
align: self.align,
is_wrapped: self.is_wrapped,
extensions: self.extensions,
}
}
pub fn align(&self) -> Option<ColumnAlign> {
self.align
}
pub fn is_wrapped(&self) -> Option<bool> {
self.is_wrapped
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
if let Some(value) = &self.align {
map.serialize_entry("align", value)?;
}
if let Some(value) = &self.is_wrapped {
map.serialize_entry("is_wrapped", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ColumnSettingsBuilder {
pub fn align(mut self, value: ColumnAlign) -> Self {
self.align = Some(value);
self
}
pub fn clear_align(mut self) -> Self {
self.align = None;
self
}
pub fn is_wrapped(mut self, value: bool) -> Self {
self.is_wrapped = Some(value);
self
}
pub fn clear_is_wrapped(mut self) -> Self {
self.is_wrapped = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ColumnSettings, ValidationError> {
let align = self.align;
let is_wrapped = self.is_wrapped;
wire::extensions(&self.extensions, &["align", "is_wrapped"], "ColumnSettings")?;
let value = ColumnSettings {
align,
is_wrapped,
extensions: self.extensions,
};
Ok(value)
}
}
impl Serialize for ColumnSettings {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ColumnSettings {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let align = wire::field::<ColumnAlign>(&mut map, "align", path)?;
let is_wrapped = wire::field::<bool>(&mut map, "is_wrapped", path)?;
ColumnSettingsBuilder {
align,
is_wrapped,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ColumnSettings {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ColumnSettings")
}
}
impl<'de> Deserialize<'de> for ColumnSettings {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ConfirmationDialogue {
title: PlainText,
text: Text,
confirm: PlainText,
deny: PlainText,
style: Option<ButtonStyle>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ConfirmationDialogueBuilder {
title: Option<PlainTextInput>,
text: Option<TextInput>,
confirm: Option<PlainTextInput>,
deny: Option<PlainTextInput>,
style: Option<ButtonStyle>,
extensions: Map<String, Value>,
}
impl Default for ConfirmationDialogueBuilder {
fn default() -> Self {
Self {
title: None,
text: None,
confirm: None,
deny: None,
style: None,
extensions: Map::new(),
}
}
}
impl ConfirmationDialogue {
pub fn builder() -> ConfirmationDialogueBuilder {
ConfirmationDialogueBuilder::default()
}
pub fn into_builder(self) -> ConfirmationDialogueBuilder {
ConfirmationDialogueBuilder {
title: Some(self.title.into()),
text: Some(self.text.into()),
confirm: Some(self.confirm.into()),
deny: Some(self.deny.into()),
style: self.style,
extensions: self.extensions,
}
}
pub fn title(&self) -> &PlainText {
&self.title
}
pub fn text(&self) -> &Text {
&self.text
}
pub fn confirm(&self) -> &PlainText {
&self.confirm
}
pub fn deny(&self) -> &PlainText {
&self.deny
}
pub fn style(&self) -> Option<ButtonStyle> {
self.style
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("title", &self.title)?;
map.serialize_entry("text", &self.text)?;
map.serialize_entry("confirm", &self.confirm)?;
map.serialize_entry("deny", &self.deny)?;
if let Some(value) = &self.style {
map.serialize_entry("style", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ConfirmationDialogueBuilder {
pub fn title(mut self, value: impl Into<PlainTextInput>) -> Self {
self.title = Some(value.into());
self
}
pub fn text(mut self, value: impl Into<TextInput>) -> Self {
self.text = Some(value.into());
self
}
pub fn confirm(mut self, value: impl Into<PlainTextInput>) -> Self {
self.confirm = Some(value.into());
self
}
pub fn deny(mut self, value: impl Into<PlainTextInput>) -> Self {
self.deny = Some(value.into());
self
}
pub fn style(mut self, value: ButtonStyle) -> Self {
self.style = Some(value);
self
}
pub fn clear_style(mut self) -> Self {
self.style = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ConfirmationDialogue, ValidationError> {
let title = wire::required(
self.title
.map(|v| v.resolve().map_err(|e| e.at("ConfirmationDialogue.title")))
.transpose()?,
"ConfirmationDialogue.title",
)?;
let text = wire::required(
self.text
.map(|v| {
v.resolve(false)
.map_err(|e| e.at("ConfirmationDialogue.text"))
})
.transpose()?,
"ConfirmationDialogue.text",
)?;
let confirm = wire::required(
self.confirm
.map(|v| {
v.resolve()
.map_err(|e| e.at("ConfirmationDialogue.confirm"))
})
.transpose()?,
"ConfirmationDialogue.confirm",
)?;
let deny = wire::required(
self.deny
.map(|v| v.resolve().map_err(|e| e.at("ConfirmationDialogue.deny")))
.transpose()?,
"ConfirmationDialogue.deny",
)?;
let style = self.style;
wire::extensions(
&self.extensions,
&["title", "text", "confirm", "deny", "style"],
"ConfirmationDialogue",
)?;
let value = ConfirmationDialogue {
title,
text,
confirm,
deny,
style,
extensions: self.extensions,
};
{
let v = &value.title;
crate::rules::length(
v.text().chars().count(),
None,
Some(100),
"ConfirmationDialogue.title",
)?;
}
{
let v = &value.text;
crate::rules::length(
crate::rules::text_len(v),
None,
Some(300),
"ConfirmationDialogue.text",
)?;
}
{
let v = &value.confirm;
crate::rules::length(
v.text().chars().count(),
None,
Some(30),
"ConfirmationDialogue.confirm",
)?;
}
{
let v = &value.deny;
crate::rules::length(
v.text().chars().count(),
None,
Some(30),
"ConfirmationDialogue.deny",
)?;
}
Ok(value)
}
}
impl Serialize for ConfirmationDialogue {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ConfirmationDialogue {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
crate::rules::coerce_text(map.get_mut("title"), "plain_text");
let title = wire::field::<PlainText>(&mut map, "title", path)?;
crate::rules::coerce_text(map.get_mut("text"), "mrkdwn");
let text = wire::field::<Text>(&mut map, "text", path)?;
crate::rules::coerce_text(map.get_mut("confirm"), "plain_text");
let confirm = wire::field::<PlainText>(&mut map, "confirm", path)?;
crate::rules::coerce_text(map.get_mut("deny"), "plain_text");
let deny = wire::field::<PlainText>(&mut map, "deny", path)?;
let style = wire::field::<ButtonStyle>(&mut map, "style", path)?;
ConfirmationDialogueBuilder {
title: title.map(Into::into),
text: text.map(Into::into),
confirm: confirm.map(Into::into),
deny: deny.map(Into::into),
style,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ConfirmationDialogue {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ConfirmationDialogue")
}
}
impl<'de> Deserialize<'de> for ConfirmationDialogue {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ConversationFilter {
include: Option<Vec<String>>,
exclude_external_shared_channels: Option<bool>,
exclude_bot_users: Option<bool>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ConversationFilterBuilder {
include: Option<Vec<String>>,
exclude_external_shared_channels: Option<bool>,
exclude_bot_users: Option<bool>,
extensions: Map<String, Value>,
}
impl Default for ConversationFilterBuilder {
fn default() -> Self {
Self {
include: None,
exclude_external_shared_channels: None,
exclude_bot_users: None,
extensions: Map::new(),
}
}
}
impl ConversationFilter {
pub fn builder() -> ConversationFilterBuilder {
ConversationFilterBuilder::default()
}
pub fn into_builder(self) -> ConversationFilterBuilder {
ConversationFilterBuilder {
include: self.include,
exclude_external_shared_channels: self.exclude_external_shared_channels,
exclude_bot_users: self.exclude_bot_users,
extensions: self.extensions,
}
}
pub fn include(&self) -> Option<&[String]> {
self.include.as_deref()
}
pub fn exclude_external_shared_channels(&self) -> Option<bool> {
self.exclude_external_shared_channels
}
pub fn exclude_bot_users(&self) -> Option<bool> {
self.exclude_bot_users
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
if let Some(value) = &self.include {
map.serialize_entry("include", value)?;
}
if let Some(value) = &self.exclude_external_shared_channels {
map.serialize_entry("exclude_external_shared_channels", value)?;
}
if let Some(value) = &self.exclude_bot_users {
map.serialize_entry("exclude_bot_users", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ConversationFilterBuilder {
pub fn include<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<String>,
{
self.include = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn add_include(mut self, value: impl Into<String>) -> Self {
self.include.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn clear_include(mut self) -> Self {
self.include = None;
self
}
pub fn exclude_external_shared_channels(mut self, value: bool) -> Self {
self.exclude_external_shared_channels = Some(value);
self
}
pub fn clear_exclude_external_shared_channels(mut self) -> Self {
self.exclude_external_shared_channels = None;
self
}
pub fn exclude_bot_users(mut self, value: bool) -> Self {
self.exclude_bot_users = Some(value);
self
}
pub fn clear_exclude_bot_users(mut self) -> Self {
self.exclude_bot_users = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ConversationFilter, ValidationError> {
let include = self.include;
let exclude_external_shared_channels = self.exclude_external_shared_channels;
let exclude_bot_users = self.exclude_bot_users;
wire::extensions(
&self.extensions,
&[
"include",
"exclude_external_shared_channels",
"exclude_bot_users",
],
"ConversationFilter",
)?;
let value = ConversationFilter {
include,
exclude_external_shared_channels,
exclude_bot_users,
extensions: self.extensions,
};
if let Some(v) = &value.include {
crate::rules::length(v.len(), Some(1), None, "ConversationFilter.include")?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(
ErrorCategory::TypeMismatch,
"ConversationFilter",
e.to_string(),
)
})?;
crate::rules::validate("ConversationFilter", &wire, "ConversationFilter")?;
Ok(value)
}
}
impl Serialize for ConversationFilter {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ConversationFilter {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let include = wire::field::<Vec<String>>(&mut map, "include", path)?;
let exclude_external_shared_channels =
wire::field::<bool>(&mut map, "exclude_external_shared_channels", path)?;
let exclude_bot_users = wire::field::<bool>(&mut map, "exclude_bot_users", path)?;
ConversationFilterBuilder {
include,
exclude_external_shared_channels,
exclude_bot_users,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ConversationFilter {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ConversationFilter")
}
}
impl<'de> Deserialize<'de> for ConversationFilter {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct DataPoint {
label: String,
value: JsonNumber,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct DataPointBuilder {
label: Option<String>,
value: Option<JsonNumber>,
extensions: Map<String, Value>,
}
impl Default for DataPointBuilder {
fn default() -> Self {
Self {
label: None,
value: None,
extensions: Map::new(),
}
}
}
impl DataPoint {
pub fn builder() -> DataPointBuilder {
DataPointBuilder::default()
}
pub fn into_builder(self) -> DataPointBuilder {
DataPointBuilder {
label: Some(self.label),
value: Some(self.value),
extensions: self.extensions,
}
}
pub fn label(&self) -> &str {
&self.label
}
pub fn value(&self) -> &JsonNumber {
&self.value
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("label", &self.label)?;
map.serialize_entry("value", &self.value)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl DataPointBuilder {
pub fn label(mut self, value: impl Into<String>) -> Self {
self.label = Some(value.into());
self
}
pub fn value(mut self, value: impl Into<JsonNumber>) -> Self {
self.value = Some(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<DataPoint, ValidationError> {
let label = wire::required(self.label, "DataPoint.label")?;
let value = wire::required(self.value, "DataPoint.value")?;
wire::extensions(&self.extensions, &["label", "value"], "DataPoint")?;
let value = DataPoint {
label,
value,
extensions: self.extensions,
};
{
let v = &value.label;
crate::rules::length(v.chars().count(), None, Some(20), "DataPoint.label")?;
}
Ok(value)
}
}
impl Serialize for DataPoint {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for DataPoint {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let label = wire::field::<String>(&mut map, "label", path)?;
let value = wire::field::<JsonNumber>(&mut map, "value", path)?;
DataPointBuilder {
label,
value,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for DataPoint {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "DataPoint")
}
}
impl<'de> Deserialize<'de> for DataPoint {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct DataSeries {
name: String,
data: Vec<DataPoint>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct DataSeriesBuilder {
name: Option<String>,
data: Option<Vec<DataPoint>>,
extensions: Map<String, Value>,
}
impl Default for DataSeriesBuilder {
fn default() -> Self {
Self {
name: None,
data: None,
extensions: Map::new(),
}
}
}
impl DataSeries {
pub fn builder() -> DataSeriesBuilder {
DataSeriesBuilder::default()
}
pub fn into_builder(self) -> DataSeriesBuilder {
DataSeriesBuilder {
name: Some(self.name),
data: Some(self.data),
extensions: self.extensions,
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn data(&self) -> &[DataPoint] {
&self.data
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("name", &self.name)?;
map.serialize_entry("data", &self.data)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl DataSeriesBuilder {
pub fn name(mut self, value: impl Into<String>) -> Self {
self.name = Some(value.into());
self
}
pub fn data<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<DataPoint>,
{
self.data = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn point(mut self, value: impl Into<DataPoint>) -> Self {
self.data.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<DataSeries, ValidationError> {
let name = wire::required(self.name, "DataSeries.name")?;
let data = wire::required(self.data, "DataSeries.data")?;
wire::extensions(&self.extensions, &["name", "data"], "DataSeries")?;
let value = DataSeries {
name,
data,
extensions: self.extensions,
};
{
let v = &value.name;
crate::rules::length(v.chars().count(), None, Some(20), "DataSeries.name")?;
}
{
let v = &value.data;
crate::rules::length(v.len(), Some(1), Some(20), "DataSeries.data")?;
}
Ok(value)
}
}
impl Serialize for DataSeries {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for DataSeries {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let name = wire::field::<String>(&mut map, "name", path)?;
let data = wire::field::<Vec<DataPoint>>(&mut map, "data", path)?;
DataSeriesBuilder {
name,
data,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for DataSeries {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "DataSeries")
}
}
impl<'de> Deserialize<'de> for DataSeries {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct DispatchActionConfiguration {
trigger_actions_on: Option<Vec<String>>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct DispatchActionConfigurationBuilder {
trigger_actions_on: Option<Vec<String>>,
extensions: Map<String, Value>,
}
impl Default for DispatchActionConfigurationBuilder {
fn default() -> Self {
Self {
trigger_actions_on: None,
extensions: Map::new(),
}
}
}
impl DispatchActionConfiguration {
pub fn builder() -> DispatchActionConfigurationBuilder {
DispatchActionConfigurationBuilder::default()
}
pub fn into_builder(self) -> DispatchActionConfigurationBuilder {
DispatchActionConfigurationBuilder {
trigger_actions_on: self.trigger_actions_on,
extensions: self.extensions,
}
}
pub fn trigger_actions_on(&self) -> Option<&[String]> {
self.trigger_actions_on.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
if let Some(value) = &self.trigger_actions_on {
map.serialize_entry("trigger_actions_on", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl DispatchActionConfigurationBuilder {
pub fn trigger_actions_on<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<String>,
{
self.trigger_actions_on = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn trigger_action(mut self, value: impl Into<String>) -> Self {
self.trigger_actions_on
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_trigger_actions_on(mut self) -> Self {
self.trigger_actions_on = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<DispatchActionConfiguration, ValidationError> {
let trigger_actions_on = self.trigger_actions_on;
wire::extensions(
&self.extensions,
&["trigger_actions_on"],
"DispatchActionConfiguration",
)?;
let value = DispatchActionConfiguration {
trigger_actions_on,
extensions: self.extensions,
};
if let Some(v) = &value.trigger_actions_on {
crate::rules::length(
v.len(),
Some(1),
Some(2),
"DispatchActionConfiguration.trigger_actions_on",
)?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(
ErrorCategory::TypeMismatch,
"DispatchActionConfiguration",
e.to_string(),
)
})?;
crate::rules::validate(
"DispatchActionConfiguration",
&wire,
"DispatchActionConfiguration",
)?;
Ok(value)
}
}
impl Serialize for DispatchActionConfiguration {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for DispatchActionConfiguration {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let trigger_actions_on = wire::field::<Vec<String>>(&mut map, "trigger_actions_on", path)?;
DispatchActionConfigurationBuilder {
trigger_actions_on,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for DispatchActionConfiguration {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "DispatchActionConfiguration")
}
}
impl<'de> Deserialize<'de> for DispatchActionConfiguration {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct FeedbackButton {
text: PlainText,
value: String,
accessibility_label: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct FeedbackButtonBuilder {
text: Option<PlainTextInput>,
value: Option<String>,
accessibility_label: Option<String>,
extensions: Map<String, Value>,
}
impl Default for FeedbackButtonBuilder {
fn default() -> Self {
Self {
text: None,
value: None,
accessibility_label: None,
extensions: Map::new(),
}
}
}
impl FeedbackButton {
pub fn builder() -> FeedbackButtonBuilder {
FeedbackButtonBuilder::default()
}
pub fn into_builder(self) -> FeedbackButtonBuilder {
FeedbackButtonBuilder {
text: Some(self.text.into()),
value: Some(self.value),
accessibility_label: self.accessibility_label,
extensions: self.extensions,
}
}
pub fn text(&self) -> &PlainText {
&self.text
}
pub fn value(&self) -> &str {
&self.value
}
pub fn accessibility_label(&self) -> Option<&str> {
self.accessibility_label.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("text", &self.text)?;
map.serialize_entry("value", &self.value)?;
if let Some(value) = &self.accessibility_label {
map.serialize_entry("accessibility_label", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl FeedbackButtonBuilder {
pub fn text(mut self, value: impl Into<PlainTextInput>) -> Self {
self.text = Some(value.into());
self
}
pub fn value(mut self, value: impl Into<String>) -> Self {
self.value = Some(value.into());
self
}
pub fn accessibility_label(mut self, value: impl Into<String>) -> Self {
self.accessibility_label = Some(value.into());
self
}
pub fn clear_accessibility_label(mut self) -> Self {
self.accessibility_label = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<FeedbackButton, ValidationError> {
let text = wire::required(
self.text
.map(|v| v.resolve().map_err(|e| e.at("FeedbackButton.text")))
.transpose()?,
"FeedbackButton.text",
)?;
let value = wire::required(self.value, "FeedbackButton.value")?;
let accessibility_label = self.accessibility_label;
wire::extensions(
&self.extensions,
&["text", "value", "accessibility_label"],
"FeedbackButton",
)?;
let value = FeedbackButton {
text,
value,
accessibility_label,
extensions: self.extensions,
};
{
let v = &value.text;
crate::rules::length(
v.text().chars().count(),
None,
Some(75),
"FeedbackButton.text",
)?;
}
{
let v = &value.value;
crate::rules::length(v.chars().count(), None, Some(2000), "FeedbackButton.value")?;
}
if let Some(v) = &value.accessibility_label {
crate::rules::length(
v.chars().count(),
None,
Some(75),
"FeedbackButton.accessibility_label",
)?;
}
Ok(value)
}
}
impl Serialize for FeedbackButton {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for FeedbackButton {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
crate::rules::coerce_text(map.get_mut("text"), "plain_text");
let text = wire::field::<PlainText>(&mut map, "text", path)?;
let value = wire::field::<String>(&mut map, "value", path)?;
let accessibility_label = wire::field::<String>(&mut map, "accessibility_label", path)?;
FeedbackButtonBuilder {
text: text.map(Into::into),
value,
accessibility_label,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for FeedbackButton {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "FeedbackButton")
}
}
impl<'de> Deserialize<'de> for FeedbackButton {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct InputParameter {
name: String,
value: String,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct InputParameterBuilder {
name: Option<String>,
value: Option<String>,
extensions: Map<String, Value>,
}
impl Default for InputParameterBuilder {
fn default() -> Self {
Self {
name: None,
value: None,
extensions: Map::new(),
}
}
}
impl InputParameter {
pub fn builder() -> InputParameterBuilder {
InputParameterBuilder::default()
}
pub fn into_builder(self) -> InputParameterBuilder {
InputParameterBuilder {
name: Some(self.name),
value: Some(self.value),
extensions: self.extensions,
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn value(&self) -> &str {
&self.value
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("name", &self.name)?;
map.serialize_entry("value", &self.value)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl InputParameterBuilder {
pub fn name(mut self, value: impl Into<String>) -> Self {
self.name = Some(value.into());
self
}
pub fn value(mut self, value: impl Into<String>) -> Self {
self.value = Some(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<InputParameter, ValidationError> {
let name = wire::required(self.name, "InputParameter.name")?;
let value = wire::required(self.value, "InputParameter.value")?;
wire::extensions(&self.extensions, &["name", "value"], "InputParameter")?;
let value = InputParameter {
name,
value,
extensions: self.extensions,
};
Ok(value)
}
}
impl Serialize for InputParameter {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for InputParameter {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let name = wire::field::<String>(&mut map, "name", path)?;
let value = wire::field::<String>(&mut map, "value", path)?;
InputParameterBuilder {
name,
value,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for InputParameter {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "InputParameter")
}
}
impl<'de> Deserialize<'de> for InputParameter {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct LineChart {
series: Vec<DataSeries>,
axis_config: AxisConfig,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct LineChartBuilder {
series: Option<Vec<DataSeries>>,
axis_config: Option<AxisConfig>,
extensions: Map<String, Value>,
}
impl Default for LineChartBuilder {
fn default() -> Self {
Self {
series: None,
axis_config: None,
extensions: Map::new(),
}
}
}
impl LineChart {
pub fn builder() -> LineChartBuilder {
LineChartBuilder::default()
}
pub fn into_builder(self) -> LineChartBuilder {
LineChartBuilder {
series: Some(self.series),
axis_config: Some(self.axis_config),
extensions: self.extensions,
}
}
pub fn series(&self) -> &[DataSeries] {
&self.series
}
pub fn axis_config(&self) -> &AxisConfig {
&self.axis_config
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "line")?;
map.serialize_entry("series", &self.series)?;
map.serialize_entry("axis_config", &self.axis_config)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl LineChartBuilder {
pub fn series<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<DataSeries>,
{
self.series = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn series_entry(mut self, value: impl Into<DataSeries>) -> Self {
self.series.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn axis_config(mut self, value: impl Into<AxisConfig>) -> Self {
self.axis_config = Some(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<LineChart, ValidationError> {
let series = wire::required(self.series, "LineChart.series")?;
let axis_config = wire::required(self.axis_config, "LineChart.axis_config")?;
wire::extensions(&self.extensions, &["series", "axis_config"], "LineChart")?;
let value = LineChart {
series,
axis_config,
extensions: self.extensions,
};
{
let v = &value.series;
crate::rules::length(v.len(), Some(1), Some(12), "LineChart.series")?;
}
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "LineChart", e.to_string())
})?;
crate::rules::validate("LineChart", &wire, "LineChart")?;
Ok(value)
}
}
impl Serialize for LineChart {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for LineChart {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "line", path)?;
let series = wire::field::<Vec<DataSeries>>(&mut map, "series", path)?;
let axis_config = wire::field::<AxisConfig>(&mut map, "axis_config", path)?;
LineChartBuilder {
series,
axis_config,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for LineChart {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "LineChart")
}
}
impl<'de> Deserialize<'de> for LineChart {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct MarkdownText {
text: String,
verbatim: Option<bool>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct MarkdownTextBuilder {
text: Option<String>,
verbatim: Option<bool>,
extensions: Map<String, Value>,
}
impl Default for MarkdownTextBuilder {
fn default() -> Self {
Self {
text: None,
verbatim: None,
extensions: Map::new(),
}
}
}
impl MarkdownText {
pub fn builder() -> MarkdownTextBuilder {
MarkdownTextBuilder::default()
}
pub fn new(text: impl Into<String>) -> Result<Self, ValidationError> {
Self::builder().text(text).build()
}
pub fn into_builder(self) -> MarkdownTextBuilder {
MarkdownTextBuilder {
text: Some(self.text),
verbatim: self.verbatim,
extensions: self.extensions,
}
}
pub fn text(&self) -> &str {
&self.text
}
pub fn verbatim(&self) -> Option<bool> {
self.verbatim
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "mrkdwn")?;
map.serialize_entry("text", &self.text)?;
if let Some(value) = &self.verbatim {
map.serialize_entry("verbatim", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl MarkdownTextBuilder {
pub fn text(mut self, value: impl Into<String>) -> Self {
self.text = Some(value.into());
self
}
pub fn verbatim(mut self, value: bool) -> Self {
self.verbatim = Some(value);
self
}
pub fn clear_verbatim(mut self) -> Self {
self.verbatim = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<MarkdownText, ValidationError> {
let text = wire::required(self.text, "MarkdownText.text")?;
let verbatim = self.verbatim;
wire::extensions(&self.extensions, &["text", "verbatim"], "MarkdownText")?;
let value = MarkdownText {
text,
verbatim,
extensions: self.extensions,
};
{
let v = &value.text;
crate::rules::length(v.chars().count(), Some(1), Some(3000), "MarkdownText.text")?;
}
Ok(value)
}
}
impl Serialize for MarkdownText {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for MarkdownText {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "mrkdwn", path)?;
let text = wire::field::<String>(&mut map, "text", path)?;
let verbatim = wire::field::<bool>(&mut map, "verbatim", path)?;
MarkdownTextBuilder {
text,
verbatim,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for MarkdownText {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "MarkdownText")
}
}
impl<'de> Deserialize<'de> for MarkdownText {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct SelectOption {
text: Text,
value: String,
description: Option<Text>,
url: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct SelectOptionBuilder {
text: Option<TextInput>,
value: Option<String>,
description: Option<TextInput>,
url: Option<String>,
extensions: Map<String, Value>,
}
impl Default for SelectOptionBuilder {
fn default() -> Self {
Self {
text: None,
value: None,
description: None,
url: None,
extensions: Map::new(),
}
}
}
impl SelectOption {
pub fn builder() -> SelectOptionBuilder {
SelectOptionBuilder::default()
}
pub fn into_builder(self) -> SelectOptionBuilder {
SelectOptionBuilder {
text: Some(self.text.into()),
value: Some(self.value),
description: self.description.map(Into::into),
url: self.url,
extensions: self.extensions,
}
}
pub fn text(&self) -> &Text {
&self.text
}
pub fn value(&self) -> &str {
&self.value
}
pub fn description(&self) -> Option<&Text> {
self.description.as_ref()
}
pub fn url(&self) -> Option<&str> {
self.url.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("text", &self.text)?;
map.serialize_entry("value", &self.value)?;
if let Some(value) = &self.description {
map.serialize_entry("description", value)?;
}
if let Some(value) = &self.url {
map.serialize_entry("url", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl SelectOptionBuilder {
pub fn text(mut self, value: impl Into<TextInput>) -> Self {
self.text = Some(value.into());
self
}
pub fn value(mut self, value: impl Into<String>) -> Self {
self.value = Some(value.into());
self
}
pub fn description(mut self, value: impl Into<TextInput>) -> Self {
self.description = Some(value.into());
self
}
pub fn clear_description(mut self) -> Self {
self.description = None;
self
}
pub fn url(mut self, value: impl Into<String>) -> Self {
self.url = Some(value.into());
self
}
pub fn clear_url(mut self) -> Self {
self.url = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<SelectOption, ValidationError> {
let text = wire::required(
self.text
.map(|v| v.resolve(true).map_err(|e| e.at("SelectOption.text")))
.transpose()?,
"SelectOption.text",
)?;
let value = wire::required(self.value, "SelectOption.value")?;
let description = self
.description
.map(|v| {
v.resolve(true)
.map_err(|e| e.at("SelectOption.description"))
})
.transpose()?;
let url = self.url;
wire::extensions(
&self.extensions,
&["text", "value", "description", "url"],
"SelectOption",
)?;
let value = SelectOption {
text,
value,
description,
url,
extensions: self.extensions,
};
{
let v = &value.text;
crate::rules::length(
crate::rules::text_len(v),
None,
Some(75),
"SelectOption.text",
)?;
}
{
let v = &value.value;
crate::rules::length(v.chars().count(), None, Some(150), "SelectOption.value")?;
}
if let Some(v) = &value.description {
crate::rules::length(
crate::rules::text_len(v),
None,
Some(75),
"SelectOption.description",
)?;
}
if let Some(v) = &value.url {
crate::rules::length(v.chars().count(), None, Some(3000), "SelectOption.url")?;
}
Ok(value)
}
}
impl Serialize for SelectOption {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for SelectOption {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
crate::rules::coerce_text(map.get_mut("text"), "plain_text");
let text = wire::field::<Text>(&mut map, "text", path)?;
let value = wire::field::<String>(&mut map, "value", path)?;
crate::rules::coerce_text(map.get_mut("description"), "plain_text");
let description = wire::field::<Text>(&mut map, "description", path)?;
let url = wire::field::<String>(&mut map, "url", path)?;
SelectOptionBuilder {
text: text.map(Into::into),
value,
description: description.map(Into::into),
url,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for SelectOption {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "SelectOption")
}
}
impl<'de> Deserialize<'de> for SelectOption {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct SelectOptionGroup {
label: PlainText,
options: Vec<SelectOption>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct SelectOptionGroupBuilder {
label: Option<PlainTextInput>,
options: Option<Vec<SelectOption>>,
extensions: Map<String, Value>,
}
impl Default for SelectOptionGroupBuilder {
fn default() -> Self {
Self {
label: None,
options: None,
extensions: Map::new(),
}
}
}
impl SelectOptionGroup {
pub fn builder() -> SelectOptionGroupBuilder {
SelectOptionGroupBuilder::default()
}
pub fn into_builder(self) -> SelectOptionGroupBuilder {
SelectOptionGroupBuilder {
label: Some(self.label.into()),
options: Some(self.options),
extensions: self.extensions,
}
}
pub fn label(&self) -> &PlainText {
&self.label
}
pub fn options(&self) -> &[SelectOption] {
&self.options
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("label", &self.label)?;
map.serialize_entry("options", &self.options)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl SelectOptionGroupBuilder {
pub fn label(mut self, value: impl Into<PlainTextInput>) -> Self {
self.label = Some(value.into());
self
}
pub fn options<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<SelectOption>,
{
self.options = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn option(mut self, value: impl Into<SelectOption>) -> Self {
self.options.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<SelectOptionGroup, ValidationError> {
let label = wire::required(
self.label
.map(|v| v.resolve().map_err(|e| e.at("SelectOptionGroup.label")))
.transpose()?,
"SelectOptionGroup.label",
)?;
let options = wire::required(self.options, "SelectOptionGroup.options")?;
wire::extensions(&self.extensions, &["label", "options"], "SelectOptionGroup")?;
let value = SelectOptionGroup {
label,
options,
extensions: self.extensions,
};
{
let v = &value.label;
crate::rules::length(
v.text().chars().count(),
None,
Some(75),
"SelectOptionGroup.label",
)?;
}
{
let v = &value.options;
crate::rules::length(v.len(), Some(1), Some(100), "SelectOptionGroup.options")?;
}
Ok(value)
}
}
impl Serialize for SelectOptionGroup {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for SelectOptionGroup {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
crate::rules::coerce_text(map.get_mut("label"), "plain_text");
let label = wire::field::<PlainText>(&mut map, "label", path)?;
let options = wire::field::<Vec<SelectOption>>(&mut map, "options", path)?;
SelectOptionGroupBuilder {
label: label.map(Into::into),
options,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for SelectOptionGroup {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "SelectOptionGroup")
}
}
impl<'de> Deserialize<'de> for SelectOptionGroup {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct PieChart {
segments: Vec<ChartSegment>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct PieChartBuilder {
segments: Option<Vec<ChartSegment>>,
extensions: Map<String, Value>,
}
impl Default for PieChartBuilder {
fn default() -> Self {
Self {
segments: None,
extensions: Map::new(),
}
}
}
impl PieChart {
pub fn builder() -> PieChartBuilder {
PieChartBuilder::default()
}
pub fn into_builder(self) -> PieChartBuilder {
PieChartBuilder {
segments: Some(self.segments),
extensions: self.extensions,
}
}
pub fn segments(&self) -> &[ChartSegment] {
&self.segments
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "pie")?;
map.serialize_entry("segments", &self.segments)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl PieChartBuilder {
pub fn segments<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<ChartSegment>,
{
self.segments = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn segment(mut self, value: impl Into<ChartSegment>) -> Self {
self.segments
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<PieChart, ValidationError> {
let segments = wire::required(self.segments, "PieChart.segments")?;
wire::extensions(&self.extensions, &["segments"], "PieChart")?;
let value = PieChart {
segments,
extensions: self.extensions,
};
{
let v = &value.segments;
crate::rules::length(v.len(), Some(1), Some(12), "PieChart.segments")?;
}
Ok(value)
}
}
impl Serialize for PieChart {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for PieChart {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "pie", path)?;
let segments = wire::field::<Vec<ChartSegment>>(&mut map, "segments", path)?;
PieChartBuilder {
segments,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for PieChart {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "PieChart")
}
}
impl<'de> Deserialize<'de> for PieChart {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct PlainText {
text: String,
emoji: Option<bool>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct PlainTextBuilder {
text: Option<String>,
emoji: Option<bool>,
extensions: Map<String, Value>,
}
impl Default for PlainTextBuilder {
fn default() -> Self {
Self {
text: None,
emoji: None,
extensions: Map::new(),
}
}
}
impl PlainText {
pub fn builder() -> PlainTextBuilder {
PlainTextBuilder::default()
}
pub fn new(text: impl Into<String>) -> Result<Self, ValidationError> {
Self::builder().text(text).build()
}
pub fn into_builder(self) -> PlainTextBuilder {
PlainTextBuilder {
text: Some(self.text),
emoji: self.emoji,
extensions: self.extensions,
}
}
pub fn text(&self) -> &str {
&self.text
}
pub fn emoji(&self) -> Option<bool> {
self.emoji
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "plain_text")?;
map.serialize_entry("text", &self.text)?;
if let Some(value) = &self.emoji {
map.serialize_entry("emoji", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl PlainTextBuilder {
pub fn text(mut self, value: impl Into<String>) -> Self {
self.text = Some(value.into());
self
}
pub fn emoji(mut self, value: bool) -> Self {
self.emoji = Some(value);
self
}
pub fn clear_emoji(mut self) -> Self {
self.emoji = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<PlainText, ValidationError> {
let text = wire::required(self.text, "PlainText.text")?;
let emoji = self.emoji;
wire::extensions(&self.extensions, &["text", "emoji"], "PlainText")?;
let value = PlainText {
text,
emoji,
extensions: self.extensions,
};
{
let v = &value.text;
crate::rules::length(v.chars().count(), Some(1), Some(3000), "PlainText.text")?;
}
Ok(value)
}
}
impl Serialize for PlainText {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for PlainText {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "plain_text", path)?;
let text = wire::field::<String>(&mut map, "text", path)?;
let emoji = wire::field::<bool>(&mut map, "emoji", path)?;
PlainTextBuilder {
text,
emoji,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for PlainText {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "PlainText")
}
}
impl<'de> Deserialize<'de> for PlainText {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RawNumber {
value: JsonNumber,
text: String,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RawNumberBuilder {
value: Option<JsonNumber>,
text: Option<String>,
extensions: Map<String, Value>,
}
impl Default for RawNumberBuilder {
fn default() -> Self {
Self {
value: None,
text: None,
extensions: Map::new(),
}
}
}
impl RawNumber {
pub fn builder() -> RawNumberBuilder {
RawNumberBuilder::default()
}
pub fn into_builder(self) -> RawNumberBuilder {
RawNumberBuilder {
value: Some(self.value),
text: Some(self.text),
extensions: self.extensions,
}
}
pub fn value(&self) -> &JsonNumber {
&self.value
}
pub fn text(&self) -> &str {
&self.text
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "raw_number")?;
map.serialize_entry("value", &self.value)?;
map.serialize_entry("text", &self.text)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RawNumberBuilder {
pub fn value(mut self, value: impl Into<JsonNumber>) -> Self {
self.value = Some(value.into());
self
}
pub fn text(mut self, value: impl Into<String>) -> Self {
self.text = Some(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RawNumber, ValidationError> {
let value = wire::required(self.value, "RawNumber.value")?;
let text = wire::required(self.text, "RawNumber.text")?;
wire::extensions(&self.extensions, &["value", "text"], "RawNumber")?;
let value = RawNumber {
value,
text,
extensions: self.extensions,
};
Ok(value)
}
}
impl Serialize for RawNumber {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RawNumber {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "raw_number", path)?;
let value = wire::field::<JsonNumber>(&mut map, "value", path)?;
let text = wire::field::<String>(&mut map, "text", path)?;
RawNumberBuilder {
value,
text,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RawNumber {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RawNumber")
}
}
impl<'de> Deserialize<'de> for RawNumber {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RawText {
text: String,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RawTextBuilder {
text: Option<String>,
extensions: Map<String, Value>,
}
impl Default for RawTextBuilder {
fn default() -> Self {
Self {
text: None,
extensions: Map::new(),
}
}
}
impl RawText {
pub fn builder() -> RawTextBuilder {
RawTextBuilder::default()
}
pub fn new(text: impl Into<String>) -> Result<Self, ValidationError> {
Self::builder().text(text).build()
}
pub fn into_builder(self) -> RawTextBuilder {
RawTextBuilder {
text: Some(self.text),
extensions: self.extensions,
}
}
pub fn text(&self) -> &str {
&self.text
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "raw_text")?;
map.serialize_entry("text", &self.text)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RawTextBuilder {
pub fn text(mut self, value: impl Into<String>) -> Self {
self.text = Some(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RawText, ValidationError> {
let text = wire::required(self.text, "RawText.text")?;
wire::extensions(&self.extensions, &["text"], "RawText")?;
let value = RawText {
text,
extensions: self.extensions,
};
Ok(value)
}
}
impl Serialize for RawText {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RawText {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "raw_text", path)?;
let text = wire::field::<String>(&mut map, "text", path)?;
RawTextBuilder {
text,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RawText {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RawText")
}
}
impl<'de> Deserialize<'de> for RawText {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RichTextChannel {
channel_id: String,
style: Option<RichTextStyle>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RichTextChannelBuilder {
channel_id: Option<String>,
style: Option<RichTextStyle>,
extensions: Map<String, Value>,
}
impl Default for RichTextChannelBuilder {
fn default() -> Self {
Self {
channel_id: None,
style: None,
extensions: Map::new(),
}
}
}
impl RichTextChannel {
pub fn builder() -> RichTextChannelBuilder {
RichTextChannelBuilder::default()
}
pub fn into_builder(self) -> RichTextChannelBuilder {
RichTextChannelBuilder {
channel_id: Some(self.channel_id),
style: self.style,
extensions: self.extensions,
}
}
pub fn channel_id(&self) -> &str {
&self.channel_id
}
pub fn style(&self) -> Option<&RichTextStyle> {
self.style.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "channel")?;
map.serialize_entry("channel_id", &self.channel_id)?;
if let Some(value) = &self.style {
map.serialize_entry("style", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RichTextChannelBuilder {
pub fn channel_id(mut self, value: impl Into<String>) -> Self {
self.channel_id = Some(value.into());
self
}
pub fn style(mut self, value: RichTextStyle) -> Self {
self.style = Some(value);
self
}
pub fn clear_style(mut self) -> Self {
self.style = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RichTextChannel, ValidationError> {
let channel_id = wire::required(self.channel_id, "RichTextChannel.channel_id")?;
let style = self.style;
wire::extensions(
&self.extensions,
&["channel_id", "style"],
"RichTextChannel",
)?;
let value = RichTextChannel {
channel_id,
style,
extensions: self.extensions,
};
if let Some(v) = &value.style {
crate::rules::style(
v,
&[
"bold",
"italic",
"strike",
"highlight",
"client_highlight",
"unlink",
],
"RichTextChannel.style",
)?;
}
Ok(value)
}
}
impl Serialize for RichTextChannel {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RichTextChannel {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "channel", path)?;
let channel_id = wire::field::<String>(&mut map, "channel_id", path)?;
let style = wire::field::<RichTextStyle>(&mut map, "style", path)?;
RichTextChannelBuilder {
channel_id,
style,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RichTextChannel {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextChannel")
}
}
impl<'de> Deserialize<'de> for RichTextChannel {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RichTextCodeBlock {
elements: Vec<RichTextSectionElement>,
border: Option<i64>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RichTextCodeBlockBuilder {
elements: Option<Vec<RichTextSectionElement>>,
border: Option<i64>,
extensions: Map<String, Value>,
}
impl Default for RichTextCodeBlockBuilder {
fn default() -> Self {
Self {
elements: None,
border: None,
extensions: Map::new(),
}
}
}
impl RichTextCodeBlock {
pub fn builder() -> RichTextCodeBlockBuilder {
RichTextCodeBlockBuilder::default()
}
pub fn into_builder(self) -> RichTextCodeBlockBuilder {
RichTextCodeBlockBuilder {
elements: Some(self.elements),
border: self.border,
extensions: self.extensions,
}
}
pub fn elements(&self) -> &[RichTextSectionElement] {
&self.elements
}
pub fn border(&self) -> Option<i64> {
self.border
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "rich_text_preformatted")?;
map.serialize_entry("elements", &self.elements)?;
if let Some(value) = &self.border {
map.serialize_entry("border", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RichTextCodeBlockBuilder {
pub fn elements<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<RichTextSectionElement>,
{
self.elements = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn element(mut self, value: impl Into<RichTextSectionElement>) -> Self {
self.elements
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn border(mut self, value: i64) -> Self {
self.border = Some(value);
self
}
pub fn clear_border(mut self) -> Self {
self.border = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RichTextCodeBlock, ValidationError> {
let elements = wire::required(self.elements, "RichTextCodeBlock.elements")?;
let border = self.border;
wire::extensions(
&self.extensions,
&["elements", "border"],
"RichTextCodeBlock",
)?;
let value = RichTextCodeBlock {
elements,
border,
extensions: self.extensions,
};
if let Some(v) = &value.border {
if *v < 0 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"RichTextCodeBlock.border",
"number outside field bounds",
));
}
if *v > 1 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"RichTextCodeBlock.border",
"number outside field bounds",
));
}
}
Ok(value)
}
}
impl Serialize for RichTextCodeBlock {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RichTextCodeBlock {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "rich_text_preformatted", path)?;
let elements = wire::field::<Vec<RichTextSectionElement>>(&mut map, "elements", path)?;
let border = wire::field::<i64>(&mut map, "border", path)?;
RichTextCodeBlockBuilder {
elements,
border,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RichTextCodeBlock {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextCodeBlock")
}
}
impl<'de> Deserialize<'de> for RichTextCodeBlock {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RichTextEmoji {
name: String,
skin_tone: Option<i64>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RichTextEmojiBuilder {
name: Option<String>,
skin_tone: Option<i64>,
extensions: Map<String, Value>,
}
impl Default for RichTextEmojiBuilder {
fn default() -> Self {
Self {
name: None,
skin_tone: None,
extensions: Map::new(),
}
}
}
impl RichTextEmoji {
pub fn builder() -> RichTextEmojiBuilder {
RichTextEmojiBuilder::default()
}
pub fn into_builder(self) -> RichTextEmojiBuilder {
RichTextEmojiBuilder {
name: Some(self.name),
skin_tone: self.skin_tone,
extensions: self.extensions,
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn skin_tone(&self) -> Option<i64> {
self.skin_tone
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "emoji")?;
map.serialize_entry("name", &self.name)?;
if let Some(value) = &self.skin_tone {
map.serialize_entry("skin_tone", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RichTextEmojiBuilder {
pub fn name(mut self, value: impl Into<String>) -> Self {
self.name = Some(value.into());
self
}
pub fn skin_tone(mut self, value: i64) -> Self {
self.skin_tone = Some(value);
self
}
pub fn clear_skin_tone(mut self) -> Self {
self.skin_tone = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RichTextEmoji, ValidationError> {
let name = wire::required(self.name, "RichTextEmoji.name")?;
let skin_tone = self.skin_tone;
wire::extensions(&self.extensions, &["name", "skin_tone"], "RichTextEmoji")?;
let value = RichTextEmoji {
name,
skin_tone,
extensions: self.extensions,
};
Ok(value)
}
}
impl Serialize for RichTextEmoji {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RichTextEmoji {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "emoji", path)?;
let name = wire::field::<String>(&mut map, "name", path)?;
let skin_tone = wire::field::<i64>(&mut map, "skin_tone", path)?;
RichTextEmojiBuilder {
name,
skin_tone,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RichTextEmoji {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextEmoji")
}
}
impl<'de> Deserialize<'de> for RichTextEmoji {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RichTextLink {
url: String,
text: Option<String>,
style: Option<RichTextStyle>,
r#unsafe: Option<bool>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RichTextLinkBuilder {
url: Option<String>,
text: Option<String>,
style: Option<RichTextStyle>,
r#unsafe: Option<bool>,
extensions: Map<String, Value>,
}
impl Default for RichTextLinkBuilder {
fn default() -> Self {
Self {
url: None,
text: None,
style: None,
r#unsafe: None,
extensions: Map::new(),
}
}
}
impl RichTextLink {
pub fn builder() -> RichTextLinkBuilder {
RichTextLinkBuilder::default()
}
pub fn into_builder(self) -> RichTextLinkBuilder {
RichTextLinkBuilder {
url: Some(self.url),
text: self.text,
style: self.style,
r#unsafe: self.r#unsafe,
extensions: self.extensions,
}
}
pub fn url(&self) -> &str {
&self.url
}
pub fn text(&self) -> Option<&str> {
self.text.as_deref()
}
pub fn style(&self) -> Option<&RichTextStyle> {
self.style.as_ref()
}
pub fn r#unsafe(&self) -> Option<bool> {
self.r#unsafe
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "link")?;
map.serialize_entry("url", &self.url)?;
if let Some(value) = &self.text {
map.serialize_entry("text", value)?;
}
if let Some(value) = &self.style {
map.serialize_entry("style", value)?;
}
if let Some(value) = &self.r#unsafe {
map.serialize_entry("unsafe", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RichTextLinkBuilder {
pub fn url(mut self, value: impl Into<String>) -> Self {
self.url = Some(value.into());
self
}
pub fn text(mut self, value: impl Into<String>) -> Self {
self.text = Some(value.into());
self
}
pub fn clear_text(mut self) -> Self {
self.text = None;
self
}
pub fn style(mut self, value: RichTextStyle) -> Self {
self.style = Some(value);
self
}
pub fn clear_style(mut self) -> Self {
self.style = None;
self
}
pub fn r#unsafe(mut self, value: bool) -> Self {
self.r#unsafe = Some(value);
self
}
pub fn clear_unsafe(mut self) -> Self {
self.r#unsafe = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RichTextLink, ValidationError> {
let url = wire::required(self.url, "RichTextLink.url")?;
let text = self.text;
let style = self.style;
let r#unsafe = self.r#unsafe;
wire::extensions(
&self.extensions,
&["url", "text", "style", "unsafe"],
"RichTextLink",
)?;
let value = RichTextLink {
url,
text,
style,
r#unsafe,
extensions: self.extensions,
};
if let Some(v) = &value.style {
crate::rules::style(
v,
&["bold", "italic", "strike", "code"],
"RichTextLink.style",
)?;
}
Ok(value)
}
}
impl Serialize for RichTextLink {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RichTextLink {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "link", path)?;
let url = wire::field::<String>(&mut map, "url", path)?;
let text = wire::field::<String>(&mut map, "text", path)?;
let style = wire::field::<RichTextStyle>(&mut map, "style", path)?;
let r#unsafe = wire::field::<bool>(&mut map, "unsafe", path)?;
RichTextLinkBuilder {
url,
text,
style,
r#unsafe,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RichTextLink {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextLink")
}
}
impl<'de> Deserialize<'de> for RichTextLink {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RichTextList {
style: RichTextListStyle,
elements: Vec<RichTextSection>,
indent: Option<i64>,
offset: Option<i64>,
border: Option<i64>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RichTextListBuilder {
style: Option<RichTextListStyle>,
elements: Option<Vec<RichTextSection>>,
indent: Option<i64>,
offset: Option<i64>,
border: Option<i64>,
extensions: Map<String, Value>,
}
impl Default for RichTextListBuilder {
fn default() -> Self {
Self {
style: None,
elements: None,
indent: None,
offset: None,
border: None,
extensions: Map::new(),
}
}
}
impl RichTextList {
pub fn builder() -> RichTextListBuilder {
RichTextListBuilder::default()
}
pub fn into_builder(self) -> RichTextListBuilder {
RichTextListBuilder {
style: Some(self.style),
elements: Some(self.elements),
indent: self.indent,
offset: self.offset,
border: self.border,
extensions: self.extensions,
}
}
pub fn style(&self) -> RichTextListStyle {
self.style
}
pub fn elements(&self) -> &[RichTextSection] {
&self.elements
}
pub fn indent(&self) -> Option<i64> {
self.indent
}
pub fn offset(&self) -> Option<i64> {
self.offset
}
pub fn border(&self) -> Option<i64> {
self.border
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "rich_text_list")?;
map.serialize_entry("style", &self.style)?;
map.serialize_entry("elements", &self.elements)?;
if let Some(value) = &self.indent {
map.serialize_entry("indent", value)?;
}
if let Some(value) = &self.offset {
map.serialize_entry("offset", value)?;
}
if let Some(value) = &self.border {
map.serialize_entry("border", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RichTextListBuilder {
pub fn style(mut self, value: RichTextListStyle) -> Self {
self.style = Some(value);
self
}
pub fn elements<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<RichTextSection>,
{
self.elements = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn element(mut self, value: impl Into<RichTextSection>) -> Self {
self.elements
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn indent(mut self, value: i64) -> Self {
self.indent = Some(value);
self
}
pub fn clear_indent(mut self) -> Self {
self.indent = None;
self
}
pub fn offset(mut self, value: i64) -> Self {
self.offset = Some(value);
self
}
pub fn clear_offset(mut self) -> Self {
self.offset = None;
self
}
pub fn border(mut self, value: i64) -> Self {
self.border = Some(value);
self
}
pub fn clear_border(mut self) -> Self {
self.border = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RichTextList, ValidationError> {
let style = wire::required(self.style, "RichTextList.style")?;
let elements = wire::required(self.elements, "RichTextList.elements")?;
let indent = self.indent;
let offset = self.offset;
let border = self.border;
wire::extensions(
&self.extensions,
&["style", "elements", "indent", "offset", "border"],
"RichTextList",
)?;
let value = RichTextList {
style,
elements,
indent,
offset,
border,
extensions: self.extensions,
};
if let Some(v) = &value.indent {
if *v < 0 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"RichTextList.indent",
"number outside field bounds",
));
}
if *v > 8 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"RichTextList.indent",
"number outside field bounds",
));
}
}
if let Some(v) = &value.offset {
if *v < 0 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"RichTextList.offset",
"number outside field bounds",
));
}
}
if let Some(v) = &value.border {
if *v < 0 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"RichTextList.border",
"number outside field bounds",
));
}
if *v > 1 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"RichTextList.border",
"number outside field bounds",
));
}
}
Ok(value)
}
}
impl Serialize for RichTextList {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RichTextList {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "rich_text_list", path)?;
let style = wire::field::<RichTextListStyle>(&mut map, "style", path)?;
let elements = wire::field::<Vec<RichTextSection>>(&mut map, "elements", path)?;
let indent = wire::field::<i64>(&mut map, "indent", path)?;
let offset = wire::field::<i64>(&mut map, "offset", path)?;
let border = wire::field::<i64>(&mut map, "border", path)?;
RichTextListBuilder {
style,
elements,
indent,
offset,
border,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RichTextList {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextList")
}
}
impl<'de> Deserialize<'de> for RichTextList {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RichTextQuote {
elements: Vec<RichTextSectionElement>,
border: Option<i64>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RichTextQuoteBuilder {
elements: Option<Vec<RichTextSectionElement>>,
border: Option<i64>,
extensions: Map<String, Value>,
}
impl Default for RichTextQuoteBuilder {
fn default() -> Self {
Self {
elements: None,
border: None,
extensions: Map::new(),
}
}
}
impl RichTextQuote {
pub fn builder() -> RichTextQuoteBuilder {
RichTextQuoteBuilder::default()
}
pub fn into_builder(self) -> RichTextQuoteBuilder {
RichTextQuoteBuilder {
elements: Some(self.elements),
border: self.border,
extensions: self.extensions,
}
}
pub fn elements(&self) -> &[RichTextSectionElement] {
&self.elements
}
pub fn border(&self) -> Option<i64> {
self.border
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "rich_text_quote")?;
map.serialize_entry("elements", &self.elements)?;
if let Some(value) = &self.border {
map.serialize_entry("border", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RichTextQuoteBuilder {
pub fn elements<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<RichTextSectionElement>,
{
self.elements = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn element(mut self, value: impl Into<RichTextSectionElement>) -> Self {
self.elements
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn border(mut self, value: i64) -> Self {
self.border = Some(value);
self
}
pub fn clear_border(mut self) -> Self {
self.border = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RichTextQuote, ValidationError> {
let elements = wire::required(self.elements, "RichTextQuote.elements")?;
let border = self.border;
wire::extensions(&self.extensions, &["elements", "border"], "RichTextQuote")?;
let value = RichTextQuote {
elements,
border,
extensions: self.extensions,
};
if let Some(v) = &value.border {
if *v < 0 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"RichTextQuote.border",
"number outside field bounds",
));
}
if *v > 1 {
return Err(ValidationError::new(
ErrorCategory::OutOfRange,
"RichTextQuote.border",
"number outside field bounds",
));
}
}
Ok(value)
}
}
impl Serialize for RichTextQuote {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RichTextQuote {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "rich_text_quote", path)?;
let elements = wire::field::<Vec<RichTextSectionElement>>(&mut map, "elements", path)?;
let border = wire::field::<i64>(&mut map, "border", path)?;
RichTextQuoteBuilder {
elements,
border,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RichTextQuote {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextQuote")
}
}
impl<'de> Deserialize<'de> for RichTextQuote {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RichTextSection {
elements: Vec<RichTextSectionElement>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RichTextSectionBuilder {
elements: Option<Vec<RichTextSectionElement>>,
extensions: Map<String, Value>,
}
impl Default for RichTextSectionBuilder {
fn default() -> Self {
Self {
elements: None,
extensions: Map::new(),
}
}
}
impl RichTextSection {
pub fn builder() -> RichTextSectionBuilder {
RichTextSectionBuilder::default()
}
pub fn into_builder(self) -> RichTextSectionBuilder {
RichTextSectionBuilder {
elements: Some(self.elements),
extensions: self.extensions,
}
}
pub fn elements(&self) -> &[RichTextSectionElement] {
&self.elements
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "rich_text_section")?;
map.serialize_entry("elements", &self.elements)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RichTextSectionBuilder {
pub fn elements<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<RichTextSectionElement>,
{
self.elements = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn element(mut self, value: impl Into<RichTextSectionElement>) -> Self {
self.elements
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RichTextSection, ValidationError> {
let elements = wire::required(self.elements, "RichTextSection.elements")?;
wire::extensions(&self.extensions, &["elements"], "RichTextSection")?;
let value = RichTextSection {
elements,
extensions: self.extensions,
};
Ok(value)
}
}
impl Serialize for RichTextSection {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RichTextSection {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "rich_text_section", path)?;
let elements = wire::field::<Vec<RichTextSectionElement>>(&mut map, "elements", path)?;
RichTextSectionBuilder {
elements,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RichTextSection {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextSection")
}
}
impl<'de> Deserialize<'de> for RichTextSection {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RichTextText {
text: String,
style: Option<RichTextStyle>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RichTextTextBuilder {
text: Option<String>,
style: Option<RichTextStyle>,
extensions: Map<String, Value>,
}
impl Default for RichTextTextBuilder {
fn default() -> Self {
Self {
text: None,
style: None,
extensions: Map::new(),
}
}
}
impl RichTextText {
pub fn builder() -> RichTextTextBuilder {
RichTextTextBuilder::default()
}
pub fn new(text: impl Into<String>) -> Result<Self, ValidationError> {
Self::builder().text(text).build()
}
pub fn into_builder(self) -> RichTextTextBuilder {
RichTextTextBuilder {
text: Some(self.text),
style: self.style,
extensions: self.extensions,
}
}
pub fn text(&self) -> &str {
&self.text
}
pub fn style(&self) -> Option<&RichTextStyle> {
self.style.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "text")?;
map.serialize_entry("text", &self.text)?;
if let Some(value) = &self.style {
map.serialize_entry("style", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RichTextTextBuilder {
pub fn text(mut self, value: impl Into<String>) -> Self {
self.text = Some(value.into());
self
}
pub fn style(mut self, value: RichTextStyle) -> Self {
self.style = Some(value);
self
}
pub fn clear_style(mut self) -> Self {
self.style = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RichTextText, ValidationError> {
let text = wire::required(self.text, "RichTextText.text")?;
let style = self.style;
wire::extensions(&self.extensions, &["text", "style"], "RichTextText")?;
let value = RichTextText {
text,
style,
extensions: self.extensions,
};
if let Some(v) = &value.style {
crate::rules::style(
v,
&["bold", "italic", "strike", "code"],
"RichTextText.style",
)?;
}
Ok(value)
}
}
impl Serialize for RichTextText {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RichTextText {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "text", path)?;
let text = wire::field::<String>(&mut map, "text", path)?;
let style = wire::field::<RichTextStyle>(&mut map, "style", path)?;
RichTextTextBuilder {
text,
style,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RichTextText {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextText")
}
}
impl<'de> Deserialize<'de> for RichTextText {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RichTextUser {
user_id: String,
style: Option<RichTextStyle>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RichTextUserBuilder {
user_id: Option<String>,
style: Option<RichTextStyle>,
extensions: Map<String, Value>,
}
impl Default for RichTextUserBuilder {
fn default() -> Self {
Self {
user_id: None,
style: None,
extensions: Map::new(),
}
}
}
impl RichTextUser {
pub fn builder() -> RichTextUserBuilder {
RichTextUserBuilder::default()
}
pub fn into_builder(self) -> RichTextUserBuilder {
RichTextUserBuilder {
user_id: Some(self.user_id),
style: self.style,
extensions: self.extensions,
}
}
pub fn user_id(&self) -> &str {
&self.user_id
}
pub fn style(&self) -> Option<&RichTextStyle> {
self.style.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "user")?;
map.serialize_entry("user_id", &self.user_id)?;
if let Some(value) = &self.style {
map.serialize_entry("style", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RichTextUserBuilder {
pub fn user_id(mut self, value: impl Into<String>) -> Self {
self.user_id = Some(value.into());
self
}
pub fn style(mut self, value: RichTextStyle) -> Self {
self.style = Some(value);
self
}
pub fn clear_style(mut self) -> Self {
self.style = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RichTextUser, ValidationError> {
let user_id = wire::required(self.user_id, "RichTextUser.user_id")?;
let style = self.style;
wire::extensions(&self.extensions, &["user_id", "style"], "RichTextUser")?;
let value = RichTextUser {
user_id,
style,
extensions: self.extensions,
};
if let Some(v) = &value.style {
crate::rules::style(
v,
&[
"bold",
"italic",
"strike",
"highlight",
"client_highlight",
"unlink",
],
"RichTextUser.style",
)?;
}
Ok(value)
}
}
impl Serialize for RichTextUser {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RichTextUser {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "user", path)?;
let user_id = wire::field::<String>(&mut map, "user_id", path)?;
let style = wire::field::<RichTextStyle>(&mut map, "style", path)?;
RichTextUserBuilder {
user_id,
style,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RichTextUser {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextUser")
}
}
impl<'de> Deserialize<'de> for RichTextUser {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct RichTextUserGroup {
usergroup_id: String,
style: Option<RichTextStyle>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct RichTextUserGroupBuilder {
usergroup_id: Option<String>,
style: Option<RichTextStyle>,
extensions: Map<String, Value>,
}
impl Default for RichTextUserGroupBuilder {
fn default() -> Self {
Self {
usergroup_id: None,
style: None,
extensions: Map::new(),
}
}
}
impl RichTextUserGroup {
pub fn builder() -> RichTextUserGroupBuilder {
RichTextUserGroupBuilder::default()
}
pub fn into_builder(self) -> RichTextUserGroupBuilder {
RichTextUserGroupBuilder {
usergroup_id: Some(self.usergroup_id),
style: self.style,
extensions: self.extensions,
}
}
pub fn usergroup_id(&self) -> &str {
&self.usergroup_id
}
pub fn style(&self) -> Option<&RichTextStyle> {
self.style.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "usergroup")?;
map.serialize_entry("usergroup_id", &self.usergroup_id)?;
if let Some(value) = &self.style {
map.serialize_entry("style", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl RichTextUserGroupBuilder {
pub fn usergroup_id(mut self, value: impl Into<String>) -> Self {
self.usergroup_id = Some(value.into());
self
}
pub fn style(mut self, value: RichTextStyle) -> Self {
self.style = Some(value);
self
}
pub fn clear_style(mut self) -> Self {
self.style = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<RichTextUserGroup, ValidationError> {
let usergroup_id = wire::required(self.usergroup_id, "RichTextUserGroup.usergroup_id")?;
let style = self.style;
wire::extensions(
&self.extensions,
&["usergroup_id", "style"],
"RichTextUserGroup",
)?;
let value = RichTextUserGroup {
usergroup_id,
style,
extensions: self.extensions,
};
if let Some(v) = &value.style {
crate::rules::style(
v,
&[
"bold",
"italic",
"strike",
"highlight",
"client_highlight",
"unlink",
],
"RichTextUserGroup.style",
)?;
}
Ok(value)
}
}
impl Serialize for RichTextUserGroup {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for RichTextUserGroup {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "usergroup", path)?;
let usergroup_id = wire::field::<String>(&mut map, "usergroup_id", path)?;
let style = wire::field::<RichTextStyle>(&mut map, "style", path)?;
RichTextUserGroupBuilder {
usergroup_id,
style,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for RichTextUserGroup {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "RichTextUserGroup")
}
}
impl<'de> Deserialize<'de> for RichTextUserGroup {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct SlackFile {
id: Option<String>,
url: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct SlackFileBuilder {
id: Option<String>,
url: Option<String>,
extensions: Map<String, Value>,
}
impl Default for SlackFileBuilder {
fn default() -> Self {
Self {
id: None,
url: None,
extensions: Map::new(),
}
}
}
impl SlackFile {
pub fn builder() -> SlackFileBuilder {
SlackFileBuilder::default()
}
pub fn into_builder(self) -> SlackFileBuilder {
SlackFileBuilder {
id: self.id,
url: self.url,
extensions: self.extensions,
}
}
pub fn id(&self) -> Option<&str> {
self.id.as_deref()
}
pub fn url(&self) -> Option<&str> {
self.url.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
if let Some(value) = &self.id {
map.serialize_entry("id", value)?;
}
if let Some(value) = &self.url {
map.serialize_entry("url", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl SlackFileBuilder {
pub fn id(mut self, value: impl Into<String>) -> Self {
self.id = Some(value.into());
self
}
pub fn clear_id(mut self) -> Self {
self.id = None;
self
}
pub fn url(mut self, value: impl Into<String>) -> Self {
self.url = Some(value.into());
self
}
pub fn clear_url(mut self) -> Self {
self.url = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<SlackFile, ValidationError> {
let id = self.id;
let url = self.url;
wire::extensions(&self.extensions, &["id", "url"], "SlackFile")?;
let value = SlackFile {
id,
url,
extensions: self.extensions,
};
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "SlackFile", e.to_string())
})?;
crate::rules::validate("SlackFile", &wire, "SlackFile")?;
Ok(value)
}
}
impl Serialize for SlackFile {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for SlackFile {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let id = wire::field::<String>(&mut map, "id", path)?;
let url = wire::field::<String>(&mut map, "url", path)?;
SlackFileBuilder {
id,
url,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for SlackFile {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "SlackFile")
}
}
impl<'de> Deserialize<'de> for SlackFile {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct SlackIcon {
name: String,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct SlackIconBuilder {
name: Option<String>,
extensions: Map<String, Value>,
}
impl Default for SlackIconBuilder {
fn default() -> Self {
Self {
name: None,
extensions: Map::new(),
}
}
}
impl SlackIcon {
pub fn builder() -> SlackIconBuilder {
SlackIconBuilder::default()
}
pub fn into_builder(self) -> SlackIconBuilder {
SlackIconBuilder {
name: Some(self.name),
extensions: self.extensions,
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "icon")?;
map.serialize_entry("name", &self.name)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl SlackIconBuilder {
pub fn name(mut self, value: impl Into<String>) -> Self {
self.name = Some(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<SlackIcon, ValidationError> {
let name = wire::required(self.name, "SlackIcon.name")?;
wire::extensions(&self.extensions, &["name"], "SlackIcon")?;
let value = SlackIcon {
name,
extensions: self.extensions,
};
let wire = serde_json::to_value(&value).map_err(|e| {
ValidationError::new(ErrorCategory::TypeMismatch, "SlackIcon", e.to_string())
})?;
crate::rules::validate("SlackIcon", &wire, "SlackIcon")?;
Ok(value)
}
}
impl Serialize for SlackIcon {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for SlackIcon {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "icon", path)?;
let name = wire::field::<String>(&mut map, "name", path)?;
SlackIconBuilder {
name,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for SlackIcon {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "SlackIcon")
}
}
impl<'de> Deserialize<'de> for SlackIcon {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Trigger {
url: String,
customizable_input_parameters: Option<Vec<InputParameter>>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct TriggerBuilder {
url: Option<String>,
customizable_input_parameters: Option<Vec<InputParameter>>,
extensions: Map<String, Value>,
}
impl Default for TriggerBuilder {
fn default() -> Self {
Self {
url: None,
customizable_input_parameters: None,
extensions: Map::new(),
}
}
}
impl Trigger {
pub fn builder() -> TriggerBuilder {
TriggerBuilder::default()
}
pub fn into_builder(self) -> TriggerBuilder {
TriggerBuilder {
url: Some(self.url),
customizable_input_parameters: self.customizable_input_parameters,
extensions: self.extensions,
}
}
pub fn url(&self) -> &str {
&self.url
}
pub fn customizable_input_parameters(&self) -> Option<&[InputParameter]> {
self.customizable_input_parameters.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("url", &self.url)?;
if let Some(value) = &self.customizable_input_parameters {
map.serialize_entry("customizable_input_parameters", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl TriggerBuilder {
pub fn url(mut self, value: impl Into<String>) -> Self {
self.url = Some(value.into());
self
}
pub fn customizable_input_parameters<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<InputParameter>,
{
self.customizable_input_parameters = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn customizable_input_parameter(mut self, value: impl Into<InputParameter>) -> Self {
self.customizable_input_parameters
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_customizable_input_parameters(mut self) -> Self {
self.customizable_input_parameters = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<Trigger, ValidationError> {
let url = wire::required(self.url, "Trigger.url")?;
let customizable_input_parameters = self.customizable_input_parameters;
wire::extensions(
&self.extensions,
&["url", "customizable_input_parameters"],
"Trigger",
)?;
let value = Trigger {
url,
customizable_input_parameters,
extensions: self.extensions,
};
Ok(value)
}
}
impl Serialize for Trigger {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for Trigger {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let url = wire::field::<String>(&mut map, "url", path)?;
let customizable_input_parameters =
wire::field::<Vec<InputParameter>>(&mut map, "customizable_input_parameters", path)?;
TriggerBuilder {
url,
customizable_input_parameters,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for Trigger {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "Trigger")
}
}
impl<'de> Deserialize<'de> for Trigger {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct UrlSource {
url: String,
text: String,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct UrlSourceBuilder {
url: Option<String>,
text: Option<String>,
extensions: Map<String, Value>,
}
impl Default for UrlSourceBuilder {
fn default() -> Self {
Self {
url: None,
text: None,
extensions: Map::new(),
}
}
}
impl UrlSource {
pub fn builder() -> UrlSourceBuilder {
UrlSourceBuilder::default()
}
pub fn into_builder(self) -> UrlSourceBuilder {
UrlSourceBuilder {
url: Some(self.url),
text: Some(self.text),
extensions: self.extensions,
}
}
pub fn url(&self) -> &str {
&self.url
}
pub fn text(&self) -> &str {
&self.text
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "url")?;
map.serialize_entry("url", &self.url)?;
map.serialize_entry("text", &self.text)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl UrlSourceBuilder {
pub fn url(mut self, value: impl Into<String>) -> Self {
self.url = Some(value.into());
self
}
pub fn text(mut self, value: impl Into<String>) -> Self {
self.text = Some(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<UrlSource, ValidationError> {
let url = wire::required(self.url, "UrlSource.url")?;
let text = wire::required(self.text, "UrlSource.text")?;
wire::extensions(&self.extensions, &["url", "text"], "UrlSource")?;
let value = UrlSource {
url,
text,
extensions: self.extensions,
};
Ok(value)
}
}
impl Serialize for UrlSource {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for UrlSource {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "url", path)?;
let url = wire::field::<String>(&mut map, "url", path)?;
let text = wire::field::<String>(&mut map, "text", path)?;
UrlSourceBuilder {
url,
text,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for UrlSource {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "UrlSource")
}
}
impl<'de> Deserialize<'de> for UrlSource {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Workflow {
trigger: Trigger,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct WorkflowBuilder {
trigger: Option<Trigger>,
extensions: Map<String, Value>,
}
impl Default for WorkflowBuilder {
fn default() -> Self {
Self {
trigger: None,
extensions: Map::new(),
}
}
}
impl Workflow {
pub fn builder() -> WorkflowBuilder {
WorkflowBuilder::default()
}
pub fn into_builder(self) -> WorkflowBuilder {
WorkflowBuilder {
trigger: Some(self.trigger),
extensions: self.extensions,
}
}
pub fn trigger(&self) -> &Trigger {
&self.trigger
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("trigger", &self.trigger)?;
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl WorkflowBuilder {
pub fn trigger(mut self, value: impl Into<Trigger>) -> Self {
self.trigger = Some(value.into());
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<Workflow, ValidationError> {
let trigger = wire::required(self.trigger, "Workflow.trigger")?;
wire::extensions(&self.extensions, &["trigger"], "Workflow")?;
let value = Workflow {
trigger,
extensions: self.extensions,
};
Ok(value)
}
}
impl Serialize for Workflow {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for Workflow {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let trigger = wire::field::<Trigger>(&mut map, "trigger", path)?;
WorkflowBuilder {
trigger,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for Workflow {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "Workflow")
}
}
impl<'de> Deserialize<'de> for Workflow {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Attachment {
blocks: Vec<Block>,
color: Option<String>,
fallback: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct AttachmentBuilder {
blocks: Option<Vec<Block>>,
color: Option<String>,
fallback: Option<String>,
extensions: Map<String, Value>,
}
impl Default for AttachmentBuilder {
fn default() -> Self {
Self {
blocks: None,
color: None,
fallback: None,
extensions: Map::new(),
}
}
}
impl Attachment {
pub fn builder() -> AttachmentBuilder {
AttachmentBuilder::default()
}
pub fn into_builder(self) -> AttachmentBuilder {
AttachmentBuilder {
blocks: Some(self.blocks),
color: self.color,
fallback: self.fallback,
extensions: self.extensions,
}
}
pub fn blocks(&self) -> &[Block] {
&self.blocks
}
pub fn color(&self) -> Option<&str> {
self.color.as_deref()
}
pub fn fallback(&self) -> Option<&str> {
self.fallback.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("blocks", &self.blocks)?;
if let Some(value) = &self.color {
map.serialize_entry("color", value)?;
}
if let Some(value) = &self.fallback {
map.serialize_entry("fallback", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl AttachmentBuilder {
pub fn blocks<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<Block>,
{
self.blocks = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn block(mut self, value: impl Into<Block>) -> Self {
self.blocks.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn color(mut self, value: impl Into<String>) -> Self {
self.color = Some(value.into());
self
}
pub fn clear_color(mut self) -> Self {
self.color = None;
self
}
pub fn fallback(mut self, value: impl Into<String>) -> Self {
self.fallback = Some(value.into());
self
}
pub fn clear_fallback(mut self) -> Self {
self.fallback = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<Attachment, ValidationError> {
let blocks = wire::required(self.blocks, "Attachment.blocks")?;
let color = self.color;
let fallback = self.fallback;
wire::extensions(
&self.extensions,
&["blocks", "color", "fallback"],
"Attachment",
)?;
let value = Attachment {
blocks,
color,
fallback,
extensions: self.extensions,
};
crate::rules::attachment(&value, "Attachment")?;
Ok(value)
}
}
impl Serialize for Attachment {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for Attachment {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let blocks = wire::field::<Vec<Block>>(&mut map, "blocks", path)?;
let color = wire::field::<String>(&mut map, "color", path)?;
let fallback = wire::field::<String>(&mut map, "fallback", path)?;
AttachmentBuilder {
blocks,
color,
fallback,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for Attachment {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "Attachment")
}
}
impl<'de> Deserialize<'de> for Attachment {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct HomeTabView {
blocks: Vec<Block>,
private_metadata: Option<String>,
callback_id: Option<String>,
external_id: Option<String>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct HomeTabViewBuilder {
blocks: Option<Vec<Block>>,
private_metadata: Option<String>,
callback_id: Option<String>,
external_id: Option<String>,
extensions: Map<String, Value>,
}
impl Default for HomeTabViewBuilder {
fn default() -> Self {
Self {
blocks: None,
private_metadata: None,
callback_id: None,
external_id: None,
extensions: Map::new(),
}
}
}
impl HomeTabView {
pub fn builder() -> HomeTabViewBuilder {
HomeTabViewBuilder::default()
}
pub fn into_builder(self) -> HomeTabViewBuilder {
HomeTabViewBuilder {
blocks: Some(self.blocks),
private_metadata: self.private_metadata,
callback_id: self.callback_id,
external_id: self.external_id,
extensions: self.extensions,
}
}
pub fn blocks(&self) -> &[Block] {
&self.blocks
}
pub fn private_metadata(&self) -> Option<&str> {
self.private_metadata.as_deref()
}
pub fn callback_id(&self) -> Option<&str> {
self.callback_id.as_deref()
}
pub fn external_id(&self) -> Option<&str> {
self.external_id.as_deref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "home")?;
map.serialize_entry("blocks", &self.blocks)?;
if let Some(value) = &self.private_metadata {
map.serialize_entry("private_metadata", value)?;
}
if let Some(value) = &self.callback_id {
map.serialize_entry("callback_id", value)?;
}
if let Some(value) = &self.external_id {
map.serialize_entry("external_id", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl HomeTabViewBuilder {
pub fn blocks<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<Block>,
{
self.blocks = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn block(mut self, value: impl Into<Block>) -> Self {
self.blocks.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn private_metadata(mut self, value: impl Into<String>) -> Self {
self.private_metadata = Some(value.into());
self
}
pub fn clear_private_metadata(mut self) -> Self {
self.private_metadata = None;
self
}
pub fn callback_id(mut self, value: impl Into<String>) -> Self {
self.callback_id = Some(value.into());
self
}
pub fn clear_callback_id(mut self) -> Self {
self.callback_id = None;
self
}
pub fn external_id(mut self, value: impl Into<String>) -> Self {
self.external_id = Some(value.into());
self
}
pub fn clear_external_id(mut self) -> Self {
self.external_id = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<HomeTabView, ValidationError> {
let blocks = wire::required(self.blocks, "HomeTabView.blocks")?;
let private_metadata = self.private_metadata;
let callback_id = self.callback_id;
let external_id = self.external_id;
wire::extensions(
&self.extensions,
&["blocks", "private_metadata", "callback_id", "external_id"],
"HomeTabView",
)?;
let value = HomeTabView {
blocks,
private_metadata,
callback_id,
external_id,
extensions: self.extensions,
};
{
let v = &value.blocks;
crate::rules::length(v.len(), None, Some(100), "HomeTabView.blocks")?;
}
if let Some(v) = &value.private_metadata {
crate::rules::length(
v.chars().count(),
None,
Some(3000),
"HomeTabView.private_metadata",
)?;
}
if let Some(v) = &value.callback_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"HomeTabView.callback_id",
)?;
}
if let Some(v) = &value.external_id {
crate::rules::length(
v.chars().count(),
None,
Some(255),
"HomeTabView.external_id",
)?;
}
crate::rules::view(value.blocks(), "home", false, "HomeTabView")?;
Ok(value)
}
}
impl Serialize for HomeTabView {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for HomeTabView {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "home", path)?;
let blocks = wire::field::<Vec<Block>>(&mut map, "blocks", path)?;
let private_metadata = wire::field::<String>(&mut map, "private_metadata", path)?;
let callback_id = wire::field::<String>(&mut map, "callback_id", path)?;
let external_id = wire::field::<String>(&mut map, "external_id", path)?;
HomeTabViewBuilder {
blocks,
private_metadata,
callback_id,
external_id,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for HomeTabView {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "HomeTabView")
}
}
impl<'de> Deserialize<'de> for HomeTabView {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct MessagePayload {
channel: String,
blocks: Option<Vec<Block>>,
attachments: Option<Vec<Attachment>>,
text: Option<String>,
mrkdwn: Option<bool>,
unfurl_links: Option<bool>,
unfurl_media: Option<bool>,
metadata: Option<Map<String, Value>>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct MessagePayloadBuilder {
channel: Option<String>,
blocks: Option<Vec<Block>>,
attachments: Option<Vec<Attachment>>,
text: Option<String>,
mrkdwn: Option<bool>,
unfurl_links: Option<bool>,
unfurl_media: Option<bool>,
metadata: Option<Map<String, Value>>,
extensions: Map<String, Value>,
}
impl Default for MessagePayloadBuilder {
fn default() -> Self {
Self {
channel: None,
blocks: None,
attachments: None,
text: Some("".into()),
mrkdwn: Some(true),
unfurl_links: None,
unfurl_media: None,
metadata: None,
extensions: Map::new(),
}
}
}
impl MessagePayload {
pub fn builder(channel: impl Into<String>) -> MessagePayloadBuilder {
MessagePayloadBuilder::default().channel(channel)
}
pub fn into_builder(self) -> MessagePayloadBuilder {
MessagePayloadBuilder {
channel: Some(self.channel),
blocks: self.blocks,
attachments: self.attachments,
text: self.text,
mrkdwn: self.mrkdwn,
unfurl_links: self.unfurl_links,
unfurl_media: self.unfurl_media,
metadata: self.metadata,
extensions: self.extensions,
}
}
pub fn channel(&self) -> &str {
&self.channel
}
pub fn blocks(&self) -> Option<&[Block]> {
self.blocks.as_deref()
}
pub fn attachments(&self) -> Option<&[Attachment]> {
self.attachments.as_deref()
}
pub fn text(&self) -> Option<&str> {
self.text.as_deref()
}
pub fn mrkdwn(&self) -> Option<bool> {
self.mrkdwn
}
pub fn unfurl_links(&self) -> Option<bool> {
self.unfurl_links
}
pub fn unfurl_media(&self) -> Option<bool> {
self.unfurl_media
}
pub fn metadata(&self) -> Option<&Map<String, Value>> {
self.metadata.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("channel", &self.channel)?;
if let Some(value) = &self.blocks {
map.serialize_entry("blocks", value)?;
}
if let Some(value) = &self.attachments {
map.serialize_entry("attachments", value)?;
}
if let Some(value) = &self.text {
map.serialize_entry("text", value)?;
}
if let Some(value) = &self.mrkdwn {
map.serialize_entry("mrkdwn", value)?;
}
if let Some(value) = &self.unfurl_links {
map.serialize_entry("unfurl_links", value)?;
}
if let Some(value) = &self.unfurl_media {
map.serialize_entry("unfurl_media", value)?;
}
if let Some(value) = &self.metadata {
map.serialize_entry("metadata", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl MessagePayloadBuilder {
pub fn channel(mut self, value: impl Into<String>) -> Self {
self.channel = Some(value.into());
self
}
pub fn blocks<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<Block>,
{
self.blocks = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn block(mut self, value: impl Into<Block>) -> Self {
self.blocks.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn clear_blocks(mut self) -> Self {
self.blocks = None;
self
}
pub fn attachments<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<Attachment>,
{
self.attachments = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn attachment(mut self, value: impl Into<Attachment>) -> Self {
self.attachments
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_attachments(mut self) -> Self {
self.attachments = None;
self
}
pub fn text(mut self, value: impl Into<String>) -> Self {
self.text = Some(value.into());
self
}
pub fn clear_text(mut self) -> Self {
self.text = None;
self
}
pub fn mrkdwn(mut self, value: bool) -> Self {
self.mrkdwn = Some(value);
self
}
pub fn clear_mrkdwn(mut self) -> Self {
self.mrkdwn = None;
self
}
pub fn unfurl_links(mut self, value: bool) -> Self {
self.unfurl_links = Some(value);
self
}
pub fn clear_unfurl_links(mut self) -> Self {
self.unfurl_links = None;
self
}
pub fn unfurl_media(mut self, value: bool) -> Self {
self.unfurl_media = Some(value);
self
}
pub fn clear_unfurl_media(mut self) -> Self {
self.unfurl_media = None;
self
}
pub fn metadata(mut self, value: Map<String, Value>) -> Self {
self.metadata = Some(value);
self
}
pub fn clear_metadata(mut self) -> Self {
self.metadata = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<MessagePayload, ValidationError> {
let channel = wire::required(self.channel, "MessagePayload.channel")?;
let blocks = self.blocks;
let attachments = self.attachments;
let text = self.text;
let mrkdwn = self.mrkdwn;
let unfurl_links = self.unfurl_links;
let unfurl_media = self.unfurl_media;
let metadata = self.metadata;
wire::extensions(
&self.extensions,
&[
"channel",
"blocks",
"attachments",
"text",
"mrkdwn",
"unfurl_links",
"unfurl_media",
"metadata",
],
"MessagePayload",
)?;
let value = MessagePayload {
channel,
blocks,
attachments,
text,
mrkdwn,
unfurl_links,
unfurl_media,
metadata,
extensions: self.extensions,
};
{
let v = &value.channel;
crate::rules::length(v.chars().count(), Some(1), None, "MessagePayload.channel")?;
}
if let Some(v) = &value.blocks {
crate::rules::length(v.len(), None, Some(50), "MessagePayload.blocks")?;
}
if let Some(v) = &value.attachments {
crate::rules::length(v.len(), None, Some(100), "MessagePayload.attachments")?;
}
crate::rules::message(
value.blocks().unwrap_or_default(),
value.attachments().unwrap_or_default(),
"MessagePayload",
)?;
Ok(value)
}
}
impl Serialize for MessagePayload {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for MessagePayload {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let channel = wire::field::<String>(&mut map, "channel", path)?;
let blocks = wire::field::<Vec<Block>>(&mut map, "blocks", path)?;
let attachments = wire::field::<Vec<Attachment>>(&mut map, "attachments", path)?;
let text = wire::field::<String>(&mut map, "text", path)?;
let mrkdwn = wire::field::<bool>(&mut map, "mrkdwn", path)?;
let unfurl_links = wire::field::<bool>(&mut map, "unfurl_links", path)?;
let unfurl_media = wire::field::<bool>(&mut map, "unfurl_media", path)?;
let metadata = wire::field::<Map<String, Value>>(&mut map, "metadata", path)?;
MessagePayloadBuilder {
channel,
blocks,
attachments,
text,
mrkdwn,
unfurl_links,
unfurl_media,
metadata,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for MessagePayload {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "MessagePayload")
}
}
impl<'de> Deserialize<'de> for MessagePayload {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct MessageResponse {
blocks: Option<Vec<Block>>,
attachments: Option<Vec<Attachment>>,
text: Option<String>,
mrkdwn: Option<bool>,
replace_original: Option<bool>,
response_type: Option<ResponseType>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct MessageResponseBuilder {
blocks: Option<Vec<Block>>,
attachments: Option<Vec<Attachment>>,
text: Option<String>,
mrkdwn: Option<bool>,
replace_original: Option<bool>,
response_type: Option<ResponseType>,
extensions: Map<String, Value>,
}
impl Default for MessageResponseBuilder {
fn default() -> Self {
Self {
blocks: None,
attachments: None,
text: Some("".into()),
mrkdwn: Some(true),
replace_original: Some(false),
response_type: Some(ResponseType::InChannel),
extensions: Map::new(),
}
}
}
impl MessageResponse {
pub fn builder() -> MessageResponseBuilder {
MessageResponseBuilder::default()
}
pub fn into_builder(self) -> MessageResponseBuilder {
MessageResponseBuilder {
blocks: self.blocks,
attachments: self.attachments,
text: self.text,
mrkdwn: self.mrkdwn,
replace_original: self.replace_original,
response_type: self.response_type,
extensions: self.extensions,
}
}
pub fn blocks(&self) -> Option<&[Block]> {
self.blocks.as_deref()
}
pub fn attachments(&self) -> Option<&[Attachment]> {
self.attachments.as_deref()
}
pub fn text(&self) -> Option<&str> {
self.text.as_deref()
}
pub fn mrkdwn(&self) -> Option<bool> {
self.mrkdwn
}
pub fn replace_original(&self) -> Option<bool> {
self.replace_original
}
pub fn response_type(&self) -> Option<ResponseType> {
self.response_type
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
if let Some(value) = &self.blocks {
map.serialize_entry("blocks", value)?;
}
if let Some(value) = &self.attachments {
map.serialize_entry("attachments", value)?;
}
if let Some(value) = &self.text {
map.serialize_entry("text", value)?;
}
if let Some(value) = &self.mrkdwn {
map.serialize_entry("mrkdwn", value)?;
}
if let Some(value) = &self.replace_original {
map.serialize_entry("replace_original", value)?;
}
if let Some(value) = &self.response_type {
map.serialize_entry("response_type", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl MessageResponseBuilder {
pub fn blocks<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<Block>,
{
self.blocks = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn block(mut self, value: impl Into<Block>) -> Self {
self.blocks.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn clear_blocks(mut self) -> Self {
self.blocks = None;
self
}
pub fn attachments<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<Attachment>,
{
self.attachments = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn attachment(mut self, value: impl Into<Attachment>) -> Self {
self.attachments
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_attachments(mut self) -> Self {
self.attachments = None;
self
}
pub fn text(mut self, value: impl Into<String>) -> Self {
self.text = Some(value.into());
self
}
pub fn clear_text(mut self) -> Self {
self.text = None;
self
}
pub fn mrkdwn(mut self, value: bool) -> Self {
self.mrkdwn = Some(value);
self
}
pub fn clear_mrkdwn(mut self) -> Self {
self.mrkdwn = None;
self
}
pub fn replace_original(mut self, value: bool) -> Self {
self.replace_original = Some(value);
self
}
pub fn clear_replace_original(mut self) -> Self {
self.replace_original = None;
self
}
pub fn response_type(mut self, value: ResponseType) -> Self {
self.response_type = Some(value);
self
}
pub fn clear_response_type(mut self) -> Self {
self.response_type = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<MessageResponse, ValidationError> {
let blocks = self.blocks;
let attachments = self.attachments;
let text = self.text;
let mrkdwn = self.mrkdwn;
let replace_original = self.replace_original;
let response_type = self.response_type;
wire::extensions(
&self.extensions,
&[
"blocks",
"attachments",
"text",
"mrkdwn",
"replace_original",
"response_type",
],
"MessageResponse",
)?;
let value = MessageResponse {
blocks,
attachments,
text,
mrkdwn,
replace_original,
response_type,
extensions: self.extensions,
};
if let Some(v) = &value.blocks {
crate::rules::length(v.len(), None, Some(50), "MessageResponse.blocks")?;
}
if let Some(v) = &value.attachments {
crate::rules::length(v.len(), None, Some(100), "MessageResponse.attachments")?;
}
crate::rules::message(
value.blocks().unwrap_or_default(),
value.attachments().unwrap_or_default(),
"MessageResponse",
)?;
Ok(value)
}
}
impl Serialize for MessageResponse {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for MessageResponse {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let blocks = wire::field::<Vec<Block>>(&mut map, "blocks", path)?;
let attachments = wire::field::<Vec<Attachment>>(&mut map, "attachments", path)?;
let text = wire::field::<String>(&mut map, "text", path)?;
let mrkdwn = wire::field::<bool>(&mut map, "mrkdwn", path)?;
let replace_original = wire::field::<bool>(&mut map, "replace_original", path)?;
let response_type = wire::field::<ResponseType>(&mut map, "response_type", path)?;
MessageResponseBuilder {
blocks,
attachments,
text,
mrkdwn,
replace_original,
response_type,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for MessageResponse {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "MessageResponse")
}
}
impl<'de> Deserialize<'de> for MessageResponse {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ModalView {
title: PlainText,
blocks: Vec<Block>,
close: Option<PlainText>,
submit: Option<PlainText>,
private_metadata: Option<String>,
callback_id: Option<String>,
clear_on_close: Option<bool>,
notify_on_close: Option<bool>,
external_id: Option<String>,
submit_disabled: Option<bool>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct ModalViewBuilder {
title: Option<PlainTextInput>,
blocks: Option<Vec<Block>>,
close: Option<PlainTextInput>,
submit: Option<PlainTextInput>,
private_metadata: Option<String>,
callback_id: Option<String>,
clear_on_close: Option<bool>,
notify_on_close: Option<bool>,
external_id: Option<String>,
submit_disabled: Option<bool>,
extensions: Map<String, Value>,
}
impl Default for ModalViewBuilder {
fn default() -> Self {
Self {
title: None,
blocks: None,
close: None,
submit: None,
private_metadata: None,
callback_id: None,
clear_on_close: None,
notify_on_close: None,
external_id: None,
submit_disabled: None,
extensions: Map::new(),
}
}
}
impl ModalView {
pub fn builder() -> ModalViewBuilder {
ModalViewBuilder::default()
}
pub fn into_builder(self) -> ModalViewBuilder {
ModalViewBuilder {
title: Some(self.title.into()),
blocks: Some(self.blocks),
close: self.close.map(Into::into),
submit: self.submit.map(Into::into),
private_metadata: self.private_metadata,
callback_id: self.callback_id,
clear_on_close: self.clear_on_close,
notify_on_close: self.notify_on_close,
external_id: self.external_id,
submit_disabled: self.submit_disabled,
extensions: self.extensions,
}
}
pub fn title(&self) -> &PlainText {
&self.title
}
pub fn blocks(&self) -> &[Block] {
&self.blocks
}
pub fn close(&self) -> Option<&PlainText> {
self.close.as_ref()
}
pub fn submit(&self) -> Option<&PlainText> {
self.submit.as_ref()
}
pub fn private_metadata(&self) -> Option<&str> {
self.private_metadata.as_deref()
}
pub fn callback_id(&self) -> Option<&str> {
self.callback_id.as_deref()
}
pub fn clear_on_close(&self) -> Option<bool> {
self.clear_on_close
}
pub fn notify_on_close(&self) -> Option<bool> {
self.notify_on_close
}
pub fn external_id(&self) -> Option<&str> {
self.external_id.as_deref()
}
pub fn submit_disabled(&self) -> Option<bool> {
self.submit_disabled
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "modal")?;
map.serialize_entry("title", &self.title)?;
map.serialize_entry("blocks", &self.blocks)?;
if let Some(value) = &self.close {
map.serialize_entry("close", value)?;
}
if let Some(value) = &self.submit {
map.serialize_entry("submit", value)?;
}
if let Some(value) = &self.private_metadata {
map.serialize_entry("private_metadata", value)?;
}
if let Some(value) = &self.callback_id {
map.serialize_entry("callback_id", value)?;
}
if let Some(value) = &self.clear_on_close {
map.serialize_entry("clear_on_close", value)?;
}
if let Some(value) = &self.notify_on_close {
map.serialize_entry("notify_on_close", value)?;
}
if let Some(value) = &self.external_id {
map.serialize_entry("external_id", value)?;
}
if let Some(value) = &self.submit_disabled {
map.serialize_entry("submit_disabled", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl ModalViewBuilder {
pub fn title(mut self, value: impl Into<PlainTextInput>) -> Self {
self.title = Some(value.into());
self
}
pub fn blocks<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<Block>,
{
self.blocks = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn block(mut self, value: impl Into<Block>) -> Self {
self.blocks.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn close(mut self, value: impl Into<PlainTextInput>) -> Self {
self.close = Some(value.into());
self
}
pub fn clear_close(mut self) -> Self {
self.close = None;
self
}
pub fn submit(mut self, value: impl Into<PlainTextInput>) -> Self {
self.submit = Some(value.into());
self
}
pub fn clear_submit(mut self) -> Self {
self.submit = None;
self
}
pub fn private_metadata(mut self, value: impl Into<String>) -> Self {
self.private_metadata = Some(value.into());
self
}
pub fn clear_private_metadata(mut self) -> Self {
self.private_metadata = None;
self
}
pub fn callback_id(mut self, value: impl Into<String>) -> Self {
self.callback_id = Some(value.into());
self
}
pub fn clear_callback_id(mut self) -> Self {
self.callback_id = None;
self
}
pub fn clear_on_close(mut self, value: bool) -> Self {
self.clear_on_close = Some(value);
self
}
pub fn clear_clear_on_close(mut self) -> Self {
self.clear_on_close = None;
self
}
pub fn notify_on_close(mut self, value: bool) -> Self {
self.notify_on_close = Some(value);
self
}
pub fn clear_notify_on_close(mut self) -> Self {
self.notify_on_close = None;
self
}
pub fn external_id(mut self, value: impl Into<String>) -> Self {
self.external_id = Some(value.into());
self
}
pub fn clear_external_id(mut self) -> Self {
self.external_id = None;
self
}
pub fn submit_disabled(mut self, value: bool) -> Self {
self.submit_disabled = Some(value);
self
}
pub fn clear_submit_disabled(mut self) -> Self {
self.submit_disabled = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<ModalView, ValidationError> {
let title = wire::required(
self.title
.map(|v| v.resolve().map_err(|e| e.at("ModalView.title")))
.transpose()?,
"ModalView.title",
)?;
let blocks = wire::required(self.blocks, "ModalView.blocks")?;
let close = self
.close
.map(|v| v.resolve().map_err(|e| e.at("ModalView.close")))
.transpose()?;
let submit = self
.submit
.map(|v| v.resolve().map_err(|e| e.at("ModalView.submit")))
.transpose()?;
let private_metadata = self.private_metadata;
let callback_id = self.callback_id;
let clear_on_close = self.clear_on_close;
let notify_on_close = self.notify_on_close;
let external_id = self.external_id;
let submit_disabled = self.submit_disabled;
wire::extensions(
&self.extensions,
&[
"title",
"blocks",
"close",
"submit",
"private_metadata",
"callback_id",
"clear_on_close",
"notify_on_close",
"external_id",
"submit_disabled",
],
"ModalView",
)?;
let value = ModalView {
title,
blocks,
close,
submit,
private_metadata,
callback_id,
clear_on_close,
notify_on_close,
external_id,
submit_disabled,
extensions: self.extensions,
};
{
let v = &value.title;
crate::rules::length(v.text().chars().count(), None, Some(24), "ModalView.title")?;
}
{
let v = &value.blocks;
crate::rules::length(v.len(), None, Some(100), "ModalView.blocks")?;
}
if let Some(v) = &value.close {
crate::rules::length(v.text().chars().count(), None, Some(24), "ModalView.close")?;
}
if let Some(v) = &value.submit {
crate::rules::length(v.text().chars().count(), None, Some(24), "ModalView.submit")?;
}
if let Some(v) = &value.private_metadata {
crate::rules::length(
v.chars().count(),
None,
Some(3000),
"ModalView.private_metadata",
)?;
}
if let Some(v) = &value.callback_id {
crate::rules::length(v.chars().count(), None, Some(255), "ModalView.callback_id")?;
}
if let Some(v) = &value.external_id {
crate::rules::length(v.chars().count(), None, Some(255), "ModalView.external_id")?;
}
crate::rules::view(
value.blocks(),
"modal",
value.submit().is_some(),
"ModalView",
)?;
Ok(value)
}
}
impl Serialize for ModalView {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for ModalView {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "modal", path)?;
crate::rules::coerce_text(map.get_mut("title"), "plain_text");
let title = wire::field::<PlainText>(&mut map, "title", path)?;
let blocks = wire::field::<Vec<Block>>(&mut map, "blocks", path)?;
crate::rules::coerce_text(map.get_mut("close"), "plain_text");
let close = wire::field::<PlainText>(&mut map, "close", path)?;
crate::rules::coerce_text(map.get_mut("submit"), "plain_text");
let submit = wire::field::<PlainText>(&mut map, "submit", path)?;
let private_metadata = wire::field::<String>(&mut map, "private_metadata", path)?;
let callback_id = wire::field::<String>(&mut map, "callback_id", path)?;
let clear_on_close = wire::field::<bool>(&mut map, "clear_on_close", path)?;
let notify_on_close = wire::field::<bool>(&mut map, "notify_on_close", path)?;
let external_id = wire::field::<String>(&mut map, "external_id", path)?;
let submit_disabled = wire::field::<bool>(&mut map, "submit_disabled", path)?;
ModalViewBuilder {
title: title.map(Into::into),
blocks,
close: close.map(Into::into),
submit: submit.map(Into::into),
private_metadata,
callback_id,
clear_on_close,
notify_on_close,
external_id,
submit_disabled,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for ModalView {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "ModalView")
}
}
impl<'de> Deserialize<'de> for ModalView {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct WebhookMessage {
blocks: Option<Vec<Block>>,
attachments: Option<Vec<Attachment>>,
text: Option<String>,
response_type: Option<ResponseType>,
replace_original: Option<bool>,
delete_original: Option<bool>,
unfurl_links: Option<bool>,
unfurl_media: Option<bool>,
metadata: Option<Map<String, Value>>,
extensions: Map<String, Value>,
}
#[derive(Clone, Debug)]
pub struct WebhookMessageBuilder {
blocks: Option<Vec<Block>>,
attachments: Option<Vec<Attachment>>,
text: Option<String>,
response_type: Option<ResponseType>,
replace_original: Option<bool>,
delete_original: Option<bool>,
unfurl_links: Option<bool>,
unfurl_media: Option<bool>,
metadata: Option<Map<String, Value>>,
extensions: Map<String, Value>,
}
impl Default for WebhookMessageBuilder {
fn default() -> Self {
Self {
blocks: None,
attachments: None,
text: None,
response_type: None,
replace_original: None,
delete_original: None,
unfurl_links: None,
unfurl_media: None,
metadata: None,
extensions: Map::new(),
}
}
}
impl WebhookMessage {
pub fn builder() -> WebhookMessageBuilder {
WebhookMessageBuilder::default()
}
pub fn into_builder(self) -> WebhookMessageBuilder {
WebhookMessageBuilder {
blocks: self.blocks,
attachments: self.attachments,
text: self.text,
response_type: self.response_type,
replace_original: self.replace_original,
delete_original: self.delete_original,
unfurl_links: self.unfurl_links,
unfurl_media: self.unfurl_media,
metadata: self.metadata,
extensions: self.extensions,
}
}
pub fn blocks(&self) -> Option<&[Block]> {
self.blocks.as_deref()
}
pub fn attachments(&self) -> Option<&[Attachment]> {
self.attachments.as_deref()
}
pub fn text(&self) -> Option<&str> {
self.text.as_deref()
}
pub fn response_type(&self) -> Option<ResponseType> {
self.response_type
}
pub fn replace_original(&self) -> Option<bool> {
self.replace_original
}
pub fn delete_original(&self) -> Option<bool> {
self.delete_original
}
pub fn unfurl_links(&self) -> Option<bool> {
self.unfurl_links
}
pub fn unfurl_media(&self) -> Option<bool> {
self.unfurl_media
}
pub fn metadata(&self) -> Option<&Map<String, Value>> {
self.metadata.as_ref()
}
pub fn extensions(&self) -> &Map<String, Value> {
&self.extensions
}
fn serialize_value<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
if let Some(value) = &self.blocks {
map.serialize_entry("blocks", value)?;
}
if let Some(value) = &self.attachments {
map.serialize_entry("attachments", value)?;
}
if let Some(value) = &self.text {
map.serialize_entry("text", value)?;
}
if let Some(value) = &self.response_type {
map.serialize_entry("response_type", value)?;
}
if let Some(value) = &self.replace_original {
map.serialize_entry("replace_original", value)?;
}
if let Some(value) = &self.delete_original {
map.serialize_entry("delete_original", value)?;
}
if let Some(value) = &self.unfurl_links {
map.serialize_entry("unfurl_links", value)?;
}
if let Some(value) = &self.unfurl_media {
map.serialize_entry("unfurl_media", value)?;
}
if let Some(value) = &self.metadata {
map.serialize_entry("metadata", value)?;
}
for (key, value) in &self.extensions {
map.serialize_entry(key, value)?;
}
map.end()
}
}
impl WebhookMessageBuilder {
pub fn blocks<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<Block>,
{
self.blocks = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn block(mut self, value: impl Into<Block>) -> Self {
self.blocks.get_or_insert_with(Vec::new).push(value.into());
self
}
pub fn clear_blocks(mut self) -> Self {
self.blocks = None;
self
}
pub fn attachments<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<Attachment>,
{
self.attachments = Some(values.into_iter().map(Into::into).collect());
self
}
pub fn attachment(mut self, value: impl Into<Attachment>) -> Self {
self.attachments
.get_or_insert_with(Vec::new)
.push(value.into());
self
}
pub fn clear_attachments(mut self) -> Self {
self.attachments = None;
self
}
pub fn text(mut self, value: impl Into<String>) -> Self {
self.text = Some(value.into());
self
}
pub fn clear_text(mut self) -> Self {
self.text = None;
self
}
pub fn response_type(mut self, value: ResponseType) -> Self {
self.response_type = Some(value);
self
}
pub fn clear_response_type(mut self) -> Self {
self.response_type = None;
self
}
pub fn replace_original(mut self, value: bool) -> Self {
self.replace_original = Some(value);
self
}
pub fn clear_replace_original(mut self) -> Self {
self.replace_original = None;
self
}
pub fn delete_original(mut self, value: bool) -> Self {
self.delete_original = Some(value);
self
}
pub fn clear_delete_original(mut self) -> Self {
self.delete_original = None;
self
}
pub fn unfurl_links(mut self, value: bool) -> Self {
self.unfurl_links = Some(value);
self
}
pub fn clear_unfurl_links(mut self) -> Self {
self.unfurl_links = None;
self
}
pub fn unfurl_media(mut self, value: bool) -> Self {
self.unfurl_media = Some(value);
self
}
pub fn clear_unfurl_media(mut self) -> Self {
self.unfurl_media = None;
self
}
pub fn metadata(mut self, value: Map<String, Value>) -> Self {
self.metadata = Some(value);
self
}
pub fn clear_metadata(mut self) -> Self {
self.metadata = None;
self
}
pub fn extension(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
self.extensions.insert(key.into(), value.into());
self
}
pub fn build(self) -> Result<WebhookMessage, ValidationError> {
let blocks = self.blocks;
let attachments = self.attachments;
let text = self.text;
let response_type = self.response_type;
let replace_original = self.replace_original;
let delete_original = self.delete_original;
let unfurl_links = self.unfurl_links;
let unfurl_media = self.unfurl_media;
let metadata = self.metadata;
wire::extensions(
&self.extensions,
&[
"blocks",
"attachments",
"text",
"response_type",
"replace_original",
"delete_original",
"unfurl_links",
"unfurl_media",
"metadata",
],
"WebhookMessage",
)?;
let value = WebhookMessage {
blocks,
attachments,
text,
response_type,
replace_original,
delete_original,
unfurl_links,
unfurl_media,
metadata,
extensions: self.extensions,
};
if let Some(v) = &value.blocks {
crate::rules::length(v.len(), None, Some(50), "WebhookMessage.blocks")?;
}
if let Some(v) = &value.attachments {
crate::rules::length(v.len(), None, Some(100), "WebhookMessage.attachments")?;
}
crate::rules::message(
value.blocks().unwrap_or_default(),
value.attachments().unwrap_or_default(),
"WebhookMessage",
)?;
Ok(value)
}
}
impl Serialize for WebhookMessage {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.serialize_value(s)
}
}
impl FromWire for WebhookMessage {
fn from_wire(value: Value, path: &str) -> Result<Self, ValidationError> {
let mut map = wire::object(value, "", path)?;
let blocks = wire::field::<Vec<Block>>(&mut map, "blocks", path)?;
let attachments = wire::field::<Vec<Attachment>>(&mut map, "attachments", path)?;
let text = wire::field::<String>(&mut map, "text", path)?;
let response_type = wire::field::<ResponseType>(&mut map, "response_type", path)?;
let replace_original = wire::field::<bool>(&mut map, "replace_original", path)?;
let delete_original = wire::field::<bool>(&mut map, "delete_original", path)?;
let unfurl_links = wire::field::<bool>(&mut map, "unfurl_links", path)?;
let unfurl_media = wire::field::<bool>(&mut map, "unfurl_media", path)?;
let metadata = wire::field::<Map<String, Value>>(&mut map, "metadata", path)?;
WebhookMessageBuilder {
blocks,
attachments,
text,
response_type,
replace_original,
delete_original,
unfurl_links,
unfurl_media,
metadata,
extensions: map,
}
.build()
.map_err(|e| e.at(path))
}
}
impl TryFrom<Value> for WebhookMessage {
type Error = ValidationError;
fn try_from(value: Value) -> Result<Self, ValidationError> {
Self::from_wire(value, "WebhookMessage")
}
}
impl<'de> Deserialize<'de> for WebhookMessage {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Self::try_from(Value::deserialize(deserializer)?).map_err(serde::de::Error::custom)
}
}