• Rust 的宏


    参考https://www.cnblogs.com/praying/p/14457360.html     https://zhuanlan.zhihu.com/p/342408254 (Rust过程宏入门(一)及后续)

    https://dengjianping.github.io/2019/02/28/%E5%A6%82%E4%BD%95%E7%BC%96%E5%86%99%E4%B8%80%E4%B8%AA%E8%BF%87%E7%A8%8B%E5%AE%8F(proc-macro).html

     1 写一个声明式宏(Declarative macros)add!,main.rs:

    macro_rules! add{
        // macth like arm for macro
           ($a:expr,$b:expr)=>{
        // macro expand to this code
               {
       // $a and $b will be templated using the value/variable provided to macro
                   $a+$b
               }
           }
       }
       
       fn main(){
        // call to macro, $a=1 and $b=2     
          println!("{}",add!(3,2));
    
       }

    2 过程宏有点麻烦,暂不写了

  • 相关阅读:
    一个Fragment的实例
    使用LayoutInflater添加一个布局引用
    11F:42点
    11E:分形盒
    11D:猴子摘桃
    11C:寻找边缘
    11B:夺宝探险
    10J:判断整除
    11A:篮球联赛
    10I:核电站
  • 原文地址:https://www.cnblogs.com/pu369/p/15156279.html
Copyright © 2020-2023  润新知