#[derive(Debug)] enum Cell{ s(String), f(f64), i(i64), b(bool) } #[derive(Debug)] struct Col{ title:String, data:Vec<Cell> } type DataFrame = Vec<Col>; trait Build{ fn new(self)->Cell; } impl Build for &str{ fn new(self) ->Cell { Cell::s(self.to_string()) } } impl Build for i64 { fn new(self)->Cell { Cell::i(self) } } impl Build for f64 { fn new(self)->Cell { Cell::f(self) } } macro_rules! series { () => { Col{ title:"A".to_string(), data: vec![] } }; ($t:expr => [$($c:expr), *]) => { Col{ title:String::from($t), data: vec![$(Build::new($c),)*] } } } macro_rules! df { ()=>{ vec![] }; ($($t:expr => [$($c:expr),*]),*) =>{ vec![ $(Col{ title:String::from($t), data: vec![$(Build::new($c),)*] },)* ] } } fn main(){ let df = df!["A"=>[1,2,2.2,"first"], "B"=>[3.3,1,"second"]]; println!("{:?}", df); }