Mashup: a working stable concat_idents

Build Status Latest Version Rust Documentation

The nightly-only [concat_idents!] macro in the Rust standard library is notoriously underpowered in that its concatenated identifiers can only refer to existing items, they can never be used to define something new.

This crate provides a more flexible spin on concatenating idents.

toml [dependencies] mashup = "0.1"

Mashup works with any Rust compiler version >= 1.15.0.

So tell me about concatenating idents

This crate provides a mashup! macro-generating macro. You provide mashup a mapping of arbitrary key tokens to idents that you want concatenated together, and mashup defines for you a substitution macro that substitutes your key tokens with the single concatenated ident corresponding to each one.

```rust

[macro_use]

extern crate mashup;

// Use mashup to generate a substitution macro called m. The substitution macro // will replace all occurrences of the key token "method" in its input with the // single concatenated identifier abc. mashup! { m["method"] = a b c; }

struct Struct;

m! { impl Struct { fn "method"() {} } }

fn main() { // Our struct now has an abc method. Struct::abc(); } ```

Glossary

More elaborate example

This example demonstrates some trickier uses of mashup.

```rust

[macro_use]

extern crate mashup;

const ROCKETA: &str = "/a"; const ROCKETB: &str = "/b";

macrorules! routes { ($($route:ident),*) => {{ mashup! { $( m["rocket-codegen-route" $route] = ROCKET $route; )* }

    m! {
        vec![$("rocket-codegen-route" $route),*]
    }
}}

}

fn main() { let routes = routes!(A, B); assert_eq!(routes, vec!["/a", "/b"]); } ```

Attributes

Attributes for the substitution macro, including doc comments, may be provided inside of the mashup invocation.

```rust mashup! { /// Needs better documentation. #[macro_export] m1["w"] = W w; m1["x"] = X x;

#[macro_export]
#[doc(hidden)]
m2["y"] = Y y;
m2["z"] = Z z;

} ```

Limitations


License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.