add links for 'Rust Macros' (#5963)

pull/5969/head
Ruslan Semagin 5 months ago committed by GitHub
parent a62ed919c1
commit 2874eb0a42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      src/data/roadmaps/rust/content/107-macros/100-declarative.md
  2. 6
      src/data/roadmaps/rust/content/107-macros/101-procedural.md
  3. 4
      src/data/roadmaps/rust/content/107-macros/102-domain-specific.md

@ -1,3 +1,8 @@
# Declarative Macros with macro_rules! # Declarative Macros with macro_rules!
Rust supports two types of macros, one of which is known as "declarative macros" (or simply `macro_rules!`). Declarative macros in Rust allow you to define reusable chunks of code that have some variable parts, without having to write a full function or type out the same code every time. They work a lot like functions, except they operate at the syntax level rather than the semantics. The compiler expands declarative macros at compile-time, in essence, taking the code they define and “pasting” it directly into your source code. They are defined using the `macro_rules!` keyword, followed by a name and a block of code. The name is used to invoke the macro later in your code, and the block of code is the code that will get inserted every time the macro is used. Rust supports two types of macros, one of which is known as "declarative macros" (or simply `macro_rules!`). Declarative macros in Rust allow you to define reusable chunks of code that have some variable parts, without having to write a full function or type out the same code every time. They work a lot like functions, except they operate at the syntax level rather than the semantics. The compiler expands declarative macros at compile-time, in essence, taking the code they define and “pasting” it directly into your source code. They are defined using the `macro_rules!` keyword, followed by a name and a block of code. The name is used to invoke the macro later in your code, and the block of code is the code that will get inserted every time the macro is used.
Visit the following resources to learn more:
- [@article@Rust Book: Macros](https://doc.rust-lang.org/book/ch19-06-macros.html)
- [@article@Macros by Example](https://doc.rust-lang.org/reference/macros-by-example.html)

@ -1,3 +1,7 @@
# Procedural Macros and Custom Derive # Procedural Macros and Custom Derive
Procedural macros in Rust allow you to define functions, or procedures, that operate on code at compile time. The input to these macros is a stream of tokens from the program text, and the output is a new stream of tokens that replace the macro invocation. They are defined in their own crates with a special crate type. There are three kinds of procedural macros: custom derive, attribute-like macros, and function-like macros. Custom derive macros let you define new behavior for the `derive` attribute. Attribute-like macros are invoked as item attributes, for example `#[foo(…)]`, and can be applied to any item that accepts attributes. Function-like macros look like function calls, but work with arbitrary tokens as input. Procedural macros in Rust allow you to define functions, or procedures, that operate on code at compile time. The input to these macros is a stream of tokens from the program text, and the output is a new stream of tokens that replace the macro invocation. They are defined in their own crates with a special crate type. There are three kinds of procedural macros: custom derive, attribute-like macros, and function-like macros. Custom derive macros let you define new behavior for the `derive` attribute. Attribute-like macros are invoked as item attributes, for example `#[foo(…)]`, and can be applied to any item that accepts attributes. Function-like macros look like function calls, but work with arbitrary tokens as input.
Visit the following resources to learn more:
- [@article@Procedural Macros](https://doc.rust-lang.org/reference/procedural-macros.html)

@ -1,3 +1,7 @@
# Domain-Specific Languages (DSLs) in Rust # Domain-Specific Languages (DSLs) in Rust
Domain Specific Languages (DSLs) are programming languages tailored to solve specific problems or tasks in an efficient manner. They are narrower in application than general-purpose languages because they are optimized for a specific domain or task. In Rust, Macros can be used to create DSLs due to their ability to define reusable syntax patterns and to effectively manipulate Rust syntax trees. This ability has led to a variety of domain-specific languages based on Rust macros, with applications ranging from game development to web application programming. Macros essentially allow Rust programmers to extend the language in ways that are tailor-made for their specific project or domain, hence creating domain-specific languages. Domain Specific Languages (DSLs) are programming languages tailored to solve specific problems or tasks in an efficient manner. They are narrower in application than general-purpose languages because they are optimized for a specific domain or task. In Rust, Macros can be used to create DSLs due to their ability to define reusable syntax patterns and to effectively manipulate Rust syntax trees. This ability has led to a variety of domain-specific languages based on Rust macros, with applications ranging from game development to web application programming. Macros essentially allow Rust programmers to extend the language in ways that are tailor-made for their specific project or domain, hence creating domain-specific languages.
Visit the following resources to learn more:
- [@article@Rust by Example: Domain Specific Languages (DSLs)](https://doc.rust-lang.org/rust-by-example/macros/dsl.html)

Loading…
Cancel
Save