use twilight_model::channel::message::{Component, component::ActionRow};
#[derive(Clone, Debug, Eq, PartialEq)]
#[must_use = "must be built into an ActionRow"]
pub struct ActionRowBuilder(ActionRow);
impl ActionRowBuilder {
pub const fn new() -> Self {
Self(ActionRow {
id: None,
components: Vec::new(),
})
}
pub fn component(mut self, component: impl Into<Component>) -> Self {
self.0.components.push(component.into());
self
}
pub const fn id(mut self, id: i32) -> Self {
self.0.id.replace(id);
self
}
pub fn build(self) -> ActionRow {
self.0
}
}
impl Default for ActionRowBuilder {
fn default() -> Self {
Self::new()
}
}
impl From<ActionRowBuilder> for ActionRow {
fn from(builder: ActionRowBuilder) -> Self {
builder.build()
}
}
#[cfg(test)]
mod tests {
use super::*;
use static_assertions::assert_impl_all;
use std::fmt::Debug;
assert_impl_all!(ActionRowBuilder: Clone, Debug, Eq, PartialEq, Send, Sync);
assert_impl_all!(ActionRow: From<ActionRowBuilder>);
#[test]
fn builder() {
let expected = ActionRow {
id: None,
components: Vec::new(),
};
let actual = ActionRowBuilder::new().build();
assert_eq!(actual, expected);
}
}