#macro #identifier #concatenation

nightly interpolate_idents

Useable macro identifier concatenation plugin

29 releases

Uses old Rust 2015

0.2.9 Nov 8, 2018
0.2.7 Aug 27, 2018
0.2.5 Jun 16, 2018
0.2.4 Mar 26, 2018
0.0.1 Mar 22, 2015

#821 in Rust patterns

Download history 10/week @ 2023-11-13 10/week @ 2023-11-20 11/week @ 2023-11-27 3/week @ 2023-12-04 8/week @ 2023-12-11 9/week @ 2023-12-18 9/week @ 2023-12-25 4/week @ 2024-01-01 9/week @ 2024-01-08 6/week @ 2024-01-15 6/week @ 2024-01-22 5/week @ 2024-01-29 7/week @ 2024-02-05 66/week @ 2024-02-12 253/week @ 2024-02-19 33/week @ 2024-02-26

359 downloads per month
Used in 4 crates

MIT license

11KB
188 lines

interpolate_idents

Deprecation warning

Because of the introduction of stable procedural macro support in Rust 1.30.0, it is now possible to accomplish what this crate set out to accomplish using entirely stable code. Please try @dtolnay's paste crate to see if it can fulfill all of your current use cases. paste can be used in stable production environments and is not nearly as prone to breakage between Rust versions.

Ideally, we will deprecate interpolate_idents as soon as we are confident that no users of this crate are left behind in the transition to paste. Please comment on issue #45 or open a new issue with any concerns and personal experiences. Thank you!

Summary

Travis-CI Status

Warning! This crate uses a procedural macro (known today as a compiler plugin) and can only be used with Rust's nightly distribution.

You cannot currently define a struct, enum, function, or field using concat_idents! due to the way macros are parsed by the Rust compiler. This will hopefully change in the future, but interpolate_idents! sloppily solves a side effect of the currently lacking macro system today.

#![feature(plugin)]
#![plugin(interpolate_idents)]

macro_rules! make_fn {
    ($x:ident) => ( interpolate_idents! {
        fn [my_ $x _fn]() -> u32 { 1000 }
    } )
}

Now make_fn!(favorite); is equivalent to fn my_favorite_fn() -> u32 { 1000 }.

In short, surround multiple space-separated identifiers (or macro identifer variables) with square brackets to concatenate the identifiers. Check tests/tests.rs for another example.

This plugin was quickly hacked together. It is likely not performant and most certainly not readable.

Crate upkeep

I'm not actively developing on nightly, so I haven't been using this plugin too often. I understand that libsyntax is a fickle beast, so please file an issue or PR if interpolate_idents fails to compile on the latest nightly!

No runtime deps