1use std::sync::Arc;
4
5#[cfg(feature = "rich-text")]
6use super::RichTextColumn;
7use super::{
8 BooleanColumn, BoxColumn, ColorColumn, Column, ComputedColumn, CountColumn, DateColumn,
9 EmbeddedColumn, FileColumn, IconColumn, ImageColumn, ListColumn, RelationColumn,
10 RepeaterColumn, SelectColumn, TextColumn, TextInputColumn, ToggleColumn,
11};
12
13pub trait IntoColumns<M> {
43 fn into_columns(self) -> Vec<BoxColumn<M>>;
45}
46
47macro_rules! column_conversions {
49 ($($ty:ident<$($g:ident),+>),+ $(,)?) => {
50 $(
51 impl<$($g),+> IntoColumns<M> for $ty<$($g),+>
52 where
53 Self: Column<M> + 'static,
54 {
55 fn into_columns(self) -> Vec<BoxColumn<M>> {
56 vec![Arc::new(self)]
57 }
58 }
59 )+
60 };
61}
62
63column_conversions!(
64 TextColumn<M, T>,
65 DateColumn<M, T>,
66 ComputedColumn<M>,
67 RelationColumn<M>,
68 CountColumn<M>,
69 BooleanColumn<M>,
70 FileColumn<M>,
71 ColorColumn<M, T>,
72 IconColumn<M, T>,
73 ImageColumn<M, T>,
74 EmbeddedColumn<M, T>,
75 ListColumn<M, T>,
76 RepeaterColumn<M, T>,
77 ToggleColumn<M>,
78 SelectColumn<M, T>,
79 TextInputColumn<M, T>,
80);
81#[cfg(feature = "rich-text")]
82column_conversions!(RichTextColumn<M, T>);
83
84impl<M> IntoColumns<M> for () {
85 fn into_columns(self) -> Vec<BoxColumn<M>> {
86 Vec::new()
87 }
88}
89
90impl<M> IntoColumns<M> for BoxColumn<M> {
91 fn into_columns(self) -> Vec<BoxColumn<M>> {
92 vec![self]
93 }
94}
95
96impl<M> IntoColumns<M> for Vec<BoxColumn<M>> {
97 fn into_columns(self) -> Vec<BoxColumn<M>> {
98 self
99 }
100}
101
102impl<M> IntoColumns<M> for &[BoxColumn<M>] {
103 fn into_columns(self) -> Vec<BoxColumn<M>> {
104 self.to_vec()
105 }
106}
107
108macro_rules! into_columns_tuples {
110 ($($T:ident => $v:ident),+ $(,)?) => {
111 impl<M, $($T),+> IntoColumns<M> for ($($T,)+)
112 where
113 $($T: IntoColumns<M>,)+
114 {
115 fn into_columns(self) -> Vec<BoxColumn<M>> {
116 let ($($v,)+) = self;
117 let mut columns = Vec::new();
118 $( columns.extend($v.into_columns()); )+
119 columns
120 }
121 }
122 };
123}
124
125into_columns_tuples!(A => a);
126into_columns_tuples!(A => a, B => b);
127into_columns_tuples!(A => a, B => b, C => c);
128into_columns_tuples!(A => a, B => b, C => c, D => d);
129into_columns_tuples!(A => a, B => b, C => c, D => d, E => e);
130into_columns_tuples!(A => a, B => b, C => c, D => d, E => e, F => f);
131into_columns_tuples!(A => a, B => b, C => c, D => d, E => e, F => f, G => g);
132into_columns_tuples!(
133 A => a, B => b, C => c, D => d, E => e, F => f, G => g, H => h
134);
135into_columns_tuples!(
136 A => a, B => b, C => c, D => d, E => e, F => f, G => g, H => h, I => i
137);
138into_columns_tuples!(
139 A => a, B => b, C => c, D => d, E => e, F => f, G => g, H => h, I => i, J => j
140);
141into_columns_tuples!(
142 A => a, B => b, C => c, D => d, E => e, F => f, G => g, H => h, I => i, J => j, K => k
143);
144into_columns_tuples!(
145 A => a, B => b, C => c, D => d, E => e, F => f, G => g, H => h, I => i, J => j, K => k, L => l
146);