Repository: serenity-rs/serenity (language: rust)

Issue:
Use `Cow<[T]>` for `CreateActionRow::Buttons`
Currently there is a forced but silly allocation here, this would require a user to use `Cow` if constructing the variant directly but possible helper of `CreateActionRow::buttons` which takes `impl Into<Cow>` could help. 


Discussion / hints:

Fix patch:
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<CreateButton<'a>>),
+    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<Cow<'a, [CreateButton<'a>]>>) -> Self {
+        Self::Buttons(buttons.into())
+    }
+
+    pub fn select_menu(select_menu: impl Into<CreateSelectMenu<'a>>) -> Self {
+        Self::SelectMenu(select_menu.into())
+    }
+
+    pub fn input_text(input_text: impl Into<CreateInputText<'a>>) -> Self {
+        Self::InputText(input_text.into())
+    }
+}
+
 impl<'a> serde::Serialize for CreateActionRow<'a> {
     fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
         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
         }


Test patch: