• Stars
    star
    239
  • Rank 168,763 (Top 4 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated about 1 year ago

Reviews

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

Repository Details

A Rust proc_macro_attribute to outline conversions from generic functions

momo

Keep your compile time during MOnoMOrphization badge

This is a proc_macro crate to help keeping the code footprint of generic methods in check. Often, generics are used in libraries to improve ergonomics. However, this has a cost in compile time and binary size. Optimally, one creates a small shell function that does the generic conversions and then calls an inner function, but that makes the code less readable.

Add a #[momo] annotation from this crate to split your function into an outer conversion and a private inner function. In return, you get some compile time for a tiny bit of runtime (if at all) – without impairing readability.

Conversions currently supported are Into (.into()), AsRef (.as_ref()), and AsMut (.as_mut()). See enum Conversions in code.

Notes on watt

This new updated version uses D. Tolnay's watt runtime to speed up the compile time, which was negatively affected with proc macro baggage.

The main crate uses a pre-built wasm containing the tagged version. Rebuilding the wasm can be done with the commands:

cd wasm

cargo +nightly build \
    --release \
    --target wasm32-unknown-unknown \
    -Z build-std=std,panic_abort \
    -Z build-std-features=panic_immediate_abort

# If wasm-opt is unavailable, copying the file is fine.
wasm-opt target/wasm32-unknown-unknown/release/momo_watt.wasm -Oz \
--strip-debug --simplify-globals --vacuum -o ../src/momo.wasm

You might need to add the wasm32-unknown-unknown target to your Rust toolchain.

(If you are tagging a new version, remember to commit the new wasm file. Also change the versions in both Cargo.toml files.)

Debugging the macro

The cargo-expand tool may be used to expand the output of macro expansion, including from this proc-macro. To examine the results of the example file, use cargo expand --example check.

More Repositories

1

flame

An intrusive flamegraph profiling tool for rust.
Rust
672
star
2

mutagen

Breaking your Rust code for fun and profit
Rust
621
star
3

flamer

A compiler plugin to insert flame calls
Rust
364
star
4

bytecount

Counting occurrences of a given byte or UTF-8 characters in a slice of memory – fast
Rust
214
star
5

stdx-dev

Rust's missing development batteries
120
star
6

metacollect

A lint to collect some crate metadata
Rust
115
star
7

overflower

A Rust compiler plugin and support library to annotate overflow behavior
Rust
103
star
8

compact_arena

A crate with indexed arenas with small memory footprint
Rust
76
star
9

optional

A small crate to provide space-efficient Option<_> replacements
Rust
35
star
10

serdebench

Rust
30
star
11

newlinebench

Rust
21
star
12

partition

partition slices in-place by a predicate
Rust
14
star
13

compressbench

A benchmark of Rust compression libraries
Rust
9
star
14

smallvectune

Rust
9
star
15

llogiq.github.io

My github page
HTML
8
star
16

pathsep

A os agnostic way to get a path separator in macros
Rust
7
star
17

extra_lints

more lints for rust (now subsumed in rust-clippy)
Rust
7
star
18

arraymap

Adds a trait to map functions over arrays
Rust
6
star
19

bsdiff-rs

A Rust BSDiff port
Rust
4
star
20

arraymapbench

A benchmark of various map methods
Rust
2
star
21

twirer

A short program I use to collect and filter the core changes for This Week In Rust
Rust
2
star
22

picnic

Your Picnic Is On Fire!
Rust
1
star
23

openpgp

Rust
1
star
24

rangeset

(WIP) a RangeSet implementation
Rust
1
star
25

typetree

a data structure within Rust's type system
Rust
1
star
26

rust-stockfighter

Simple Rust Wrapper for stockfigher
Rust
1
star
27

ternary

Kleene logic in Rust's type system
Rust
1
star
28

lib_json

Allocationless Json Parsing
Rust
1
star
29

wom

Write-Only Memory for Rust
Rust
1
star