• Stars
    star
    1,033
  • Rank 44,608 (Top 0.9 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Learn Macros In Rust

MacroKata

Welcome to MacroKata, a set of exercises which you can use to learn how to write macros in Rust. When completing each task, there are three goals:

  • Get your code to compile without warnings or errors.
  • Get your code to "work correctly" (i.e. produce the same output)
  • Importantly, generate the same code as what the sample solution does.

You should complete the kata in order, as they increase in difficulty, and depend on previous kata.

This set of exercises is written for people who have already spent some time programming in Rust. Before completing this, work through a Rust tutorial and build some small programs yourself.

Getting Started

Clone this repository:

$ git clone https://www.github.com/tfpk/macrokata/

You will also need to install the Rust "nightly" toolchain, so that we can show expanded macros:

$ rustup toolchain install nightly

Next, install cargo-expand:

$ cargo install cargo-expand

Build the main binary provided with this repo:

$ cargo build --bin macrokata

You can find the first kata (my_first_macro) inside exercises/01_my_first_macro. Read the first chapter of the book and get started by editing the main.rs file.

To compare your expanded code to the "goal", use the test subcommand:

$ cargo run -- test 01_my_first_macro

You can run your own code as follows:

$ cargo run --bin 01_my_first_macro

How To Learn About Procedural Macros

I was originally planning to expand macrokata into discussing procedural macros as well. As I was researching that, I found dtolnay's superlative Proc Macro Workshop. Jon Gjengset's video on proc-macros is also a phenomenal resource (despite its length).

I've put my attempt to write something like that on hold because I think the above is better in every way. Do file an issue if there's something that we could do here to complement that workshop though.

More Repositories

1

lifetimekata

An exploration of lifetimes in Rust.
Rust
249
star
2

mdbook-keeper

Rust
11
star
3

cse

Tools for use at UNSW CSE
Shell
7
star
4

nominomicon

A Work-In-Progress book for nom
Shell
4
star
5

discord_verifier

Python
4
star
6

fydb

GDB (the GNU Debugger) is a complex program. These scripts are intended for beginner C programmers to help them get used to it.
Python
3
star
7

discourse-reveal-anonymous

Reveal anonymous users' true identities as a discourse staff-member.
JavaScript
3
star
8

dewar

A flask-like static site generator
Python
3
star
9

valhalla

Valhalla is a wrapper around Valgrind. It is designed to give beginners an easier time detecting memory issues.
Python
3
star
10

os161-tools

A set of tools for os161 (the COMP3231|3891 teaching OS) to make life easier.
Shell
2
star
11

require_lifetimes

A proc-macro to force rust authors to include lifetimes in their functions.
Rust
1
star
12

lsp-proxy

A proxy between LSP clients and servers
Rust
1
star
13

RugbyScore

Displays scores on the Weigall Scoreboard.
HTML
1
star
14

QualtricsElector

A set of tools to help UNSW Societies run elections through Qualtrics
JavaScript
1
star
15

memtree

Represent memory in C programs as a directed graph.
Python
1
star
16

RSA-Implementation

An (insecure) implementation of textbook RSA.
C
1
star
17

packing

JavaScript
1
star
18

operator

CGI script to run operations remotely.
Rust
1
star
19

qualtrics_elector_web

JavaScript
1
star
20

brainfucker-rust

A Brainfuck interpreter, written in rust.
Rust
1
star
21

cs6841-find-password

Python
1
star
22

splice

Shell
1
star
23

csp

An attempt at a constraint solver for performing tutor allocations.
Python
1
star
24

cpp-calculator

CMake
1
star