<commit_before># Mixins for Rust

[![Build Status](https://travis-ci.org/huonw/external_mixin.png)](https://travis-ci.org/huonw/external_mixin)

Write code in arbitrary languages, to emit Rust code right in your
crate.

```rust
#![feature(plugin)]
#![plugin(external_mixin)]
#![plugin(rust_mixin)]

python_mixin! {"
x = 1 + 2
print('fn get_x() -> u64 { %d }' % x)
"}

fn main() {
    let value = get_x();

    let other_value = rust_mixin! {r#"
fn main() {
    println!("{}", 3 + 4);
}
    "#};

    assert_eq!(value, 3);
    assert_eq!(other_value, 7);
}
```

This comes in three libraries:

- [`rust_mixin`](#rust_mixin) — use Rust to generate your code.
- [`external_mixin`](#external_mixin) — use scripting languages like
  Python or Ruby to generate your code.
- [`external_mixin_umbrella](#external_mixin_umbrella) — support
  library, to keep the above DRY.

## Should I actually use these?

Probably not, this is me experimenting with
[more](https://github.com/huonw/brainfuck_macros) language
[plugins](https://github.com/huonw/fractran_macros). A more
portable/usable way to do this sort of code-generation is via
[a `Cargo` build script](http://doc.crates.io/build-script.html) plus
the `include!` macro.

Some downsides (not exhaustive):

- the mixins like `python_mixin!` relies on having correctly-named
  binaries in the user's path, and, e.g. "`python`" is
  sometimes Python 2 and sometimes Python 3 and it's mean to require
  users to have installed Python on Windows. (Build scripts only need
  a Cargo and a Rust compiler, which the user is guaranteed to have if
  they're trying to build your Rust code.)

- errors in the generated code are hard to debug, although the macros
  do try to give as useful error messages as possible e.g. file/line
  numbers for errors in the code point as closely as possible to the
  relevant part of the original string containing the source<commit_msg>Missed back-tick.<commit_after># Mixins for Rust

[![Build Status](https://travis-ci.org/huonw/external_mixin.png)](https://travis-ci.org/huonw/external_mixin)

Write code in arbitrary languages, to emit Rust code right in your
crate.

```rust
#![feature(plugin)]
#![plugin(external_mixin)]
#![plugin(rust_mixin)]

python_mixin! {"
x = 1 + 2
print('fn get_x() -> u64 { %d }' % x)
"}

fn main() {
    let value = get_x();

    let other_value = rust_mixin! {r#"
fn main() {
    println!("{}", 3 + 4);
}
    "#};

    assert_eq!(value, 3);
    assert_eq!(other_value, 7);
}
```

This comes in three libraries:

- [`rust_mixin`](#rust_mixin) — use Rust to generate your code.
- [`external_mixin`](#external_mixin) — use scripting languages like
  Python or Ruby to generate your code.
- [`external_mixin_umbrella`](#external_mixin_umbrella) — support
  library, to keep the above DRY.

## Should I actually use these?

Probably not, this is me experimenting with
[more](https://github.com/huonw/brainfuck_macros) language
[plugins](https://github.com/huonw/fractran_macros). A more
portable/usable way to do this sort of code-generation is via
[a `Cargo` build script](http://doc.crates.io/build-script.html) plus
the `include!` macro.

Some downsides (not exhaustive):

- the mixins like `python_mixin!` relies on having correctly-named
  binaries in the user's path, and, e.g. "`python`" is
  sometimes Python 2 and sometimes Python 3 and it's mean to require
  users to have installed Python on Windows. (Build scripts only need
  a Cargo and a Rust compiler, which the user is guaranteed to have if
  they're trying to build your Rust code.)

- errors in the generated code are hard to debug, although the macros
  do try to give as useful error messages as possible e.g. file/line
  numbers for errors in the code point as closely as possible to the
  relevant part of the original string containing the source
{'fraction_non_alphanumeric': 0.11547525530243519, 'fraction_numerical': 0.005236973029588898, 'mean_word_length': 4.232876712328767, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1285467', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1213, 'n_words': 462}