• 解析列, 表


    #[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);
    
    
    }
    

      

  • 相关阅读:
    curl库使用文件传输
    linux 命令
    第三方库交叉编译
    指针越界
    GetWindowRect GetClientRect
    libevent
    C#关闭窗体
    C# log日志窗口
    C++同一时刻仅允许一个实例,包含多用户的场景。
    C# 引用类型
  • 原文地址:https://www.cnblogs.com/pythonClub/p/16483826.html
Copyright © 2020-2023  润新知