Code Monkey home page Code Monkey logo

rust-macro-demo's Introduction

rust 相关宏

rust相关的宏,大致可以分为两大类,一类是声明式宏、另类是过程宏。

声明式宏

使用 macro_rules! 的声明来实现的宏,我们一般称之为声明式宏(Macros by Example)

过程宏

过程宏有三种类型

  • 自定义 #[derive] 宏在结构体和枚举上指定通过 derive 属性添加的代码。 custom!(...)
  • 类属性(Attribute-like)宏定义可用于任意项的自定义属性 #[derive(CustomDerive)]
  • 类函数宏看起来像函数不过作用于作为参数传递的token #[CustomAttribute]

demo

自定义声明式宏,见代码 自定义derive宏,derive_enum_from_daring

rust-macro-demo's People

Contributors

bearboy80 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.