diff --git a/src/builder/create_components.rs b/src/builder/create_components.rs index 10be84027f9..516f7aeac00 100644 --- a/src/builder/create_components.rs +++ b/src/builder/create_components.rs @@ -11,12 +11,26 @@ use crate::model::prelude::*; #[derive(Clone, Debug)] #[must_use] pub enum CreateActionRow<'a> { - Buttons(Vec>), + Buttons(Cow<'a, [CreateButton<'a>]>), SelectMenu(CreateSelectMenu<'a>), /// Only valid in modals! InputText(CreateInputText<'a>), } +impl<'a> CreateActionRow<'a> { + pub fn buttons(buttons: impl Into]>>) -> Self { + Self::Buttons(buttons.into()) + } + + pub fn select_menu(select_menu: impl Into>) -> Self { + Self::SelectMenu(select_menu.into()) + } + + pub fn input_text(input_text: impl Into>) -> Self { + Self::InputText(input_text.into()) + } +} + impl<'a> serde::Serialize for CreateActionRow<'a> { fn serialize(&self, serializer: S) -> Result { use serde::ser::Error as _; diff --git a/src/builder/mod.rs b/src/builder/mod.rs index 149e012548a..1e4065466a8 100644 --- a/src/builder/mod.rs +++ b/src/builder/mod.rs @@ -126,12 +126,12 @@ macro_rules! button_and_select_menu_convenience_methods { pub fn button(mut $self, button: super::CreateButton<'a>) -> Self { let rows = $self$(.$components_path)+.get_or_insert_with(Cow::default).to_mut(); let row_with_space_left = rows.last_mut().and_then(|row| match row { - super::CreateActionRow::Buttons(buttons) if buttons.len() < 5 => Some(buttons), + super::CreateActionRow::Buttons(buttons) if buttons.len() < 5 => Some(buttons.to_mut()), _ => None, }); match row_with_space_left { Some(row) => row.push(button), - None => rows.push(super::CreateActionRow::Buttons(vec![button])), + None => rows.push(super::CreateActionRow::buttons(vec![button])), } $self }