Crate rustplacements [] [src]

Rustplacements

This is a compiler plugin for the Rust language that replaces all of your string literals in the source code with random text. Well, it's not really random. You can choose to replace text with items from any of the lists on this page by simply adding a few attributes to your existing Rust code.

A Brief Example

Let's start with a simple example like the one below. It prints out the words in the sentence below one word at a time.

const SENTENCE: [&'static str; 9] = ["The", "Quick", "Brown", "Fox", "Jumped", "Over", "the",
                                     "Lazy", "Dog"];

fn main() {
    for word in &SENTENCE {
        println!("{}", word);
    }
}

The output should look like:

The
Quick
Brown
Fox
Jumped
Over
the
Lazy
Dog

Rustplacements let's us replace all the strings at compile with other values. Let's say we want to replace all the text with emojis. Rustplacements can do that.

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

// Placing it in the module root will replace everything in the module
#![Rustplacements = "emojis"]

const SENTENCE: [&'static str; 9] = ["The", "Quick", "Brown", "Fox", "Jumped", "Over", "the",
                                     "Lazy", "Dog"];

fn main() {
    for word in &SENTENCE {
        println!("{}", word);
    }
}

The new output will look something like this. The output is randomized so it will be re-generated everytime you compile your crate.

😢 😫 🤓
😞 😠 😟 😖 😧
😬 😬 😈 😡 😟
😓 😒 😬
😝 😘 🤧 😬 😧 😡
😗 😈 😉 😫
😄 😱 😰
😃 🤡 😅 😯
🤒 😈 😈

Using Rustplacements

Compiler plugins like Rustplacements are only available on nightly rust because they require a feature flag to use. To get started, Rustplacements is available on crates.io. To download the latest version, add the following line to the Cargo.toml.

[dependencies]
rustplacements = "*"

To enable the compiler plugin, add the following lines on the top of your main.rs or lib.rs.

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

You can now use the plugin anywhere in the crate by applying the #[Rustplacements = "one-direction"] to any language element. You can place the element in the root with #![Rustplacements = "got-quotes"] and it will transform all the string literals in your module. It can also be applied to specific strings / impls / functions for more fine grained control.

That's pretty much all there is to it. Check out the categories page for more categories that you can use.

Functions

plugin_registrar

Compiler hook for Rust to register plugins.