File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,26 @@ use crate::model::prelude::*;
1111#[ derive( Clone , Debug ) ]
1212#[ must_use]
1313pub enum CreateActionRow < ' a > {
14- Buttons ( Vec < CreateButton < ' a > > ) ,
14+ Buttons ( Cow < ' a , [ CreateButton < ' a > ] > ) ,
1515 SelectMenu ( CreateSelectMenu < ' a > ) ,
1616 /// Only valid in modals!
1717 InputText ( CreateInputText < ' a > ) ,
1818}
1919
20+ impl < ' a > CreateActionRow < ' a > {
21+ pub fn buttons ( buttons : impl Into < Cow < ' a , [ CreateButton < ' a > ] > > ) -> Self {
22+ Self :: Buttons ( buttons. into ( ) )
23+ }
24+
25+ pub fn select_menu ( select_menu : impl Into < CreateSelectMenu < ' a > > ) -> Self {
26+ Self :: SelectMenu ( select_menu. into ( ) )
27+ }
28+
29+ pub fn input_text ( input_text : impl Into < CreateInputText < ' a > > ) -> Self {
30+ Self :: InputText ( input_text. into ( ) )
31+ }
32+ }
33+
2034impl < ' a > serde:: Serialize for CreateActionRow < ' a > {
2135 fn serialize < S : serde:: Serializer > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error > {
2236 use serde:: ser:: Error as _;
Original file line number Diff line number Diff line change @@ -126,12 +126,12 @@ macro_rules! button_and_select_menu_convenience_methods {
126126 pub fn button( mut $self, button: super :: CreateButton <' a>) -> Self {
127127 let rows = $self$( . $components_path) +. get_or_insert_with( Cow :: default ) . to_mut( ) ;
128128 let row_with_space_left = rows. last_mut( ) . and_then( |row| match row {
129- super :: CreateActionRow :: Buttons ( buttons) if buttons. len( ) < 5 => Some ( buttons) ,
129+ super :: CreateActionRow :: Buttons ( buttons) if buttons. len( ) < 5 => Some ( buttons. to_mut ( ) ) ,
130130 _ => None ,
131131 } ) ;
132132 match row_with_space_left {
133133 Some ( row) => row. push( button) ,
134- None => rows. push( super :: CreateActionRow :: Buttons ( vec![ button] ) ) ,
134+ None => rows. push( super :: CreateActionRow :: buttons ( vec![ button] ) ) ,
135135 }
136136 $self
137137 }
You can’t perform that action at this time.
0 commit comments