https://github.com/williamvenner/inline-rust
A cursed macro that compiles and executes Rust and spits the output directly into your Rust code
https://github.com/williamvenner/inline-rust
embed inline macro proc-macro procmacro rust
Last synced: 30 days ago
JSON representation
A cursed macro that compiles and executes Rust and spits the output directly into your Rust code
- Host: GitHub
- URL: https://github.com/williamvenner/inline-rust
- Owner: WilliamVenner
- License: mit
- Created: 2021-11-22T20:50:17.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-11-26T13:29:39.000Z (over 2 years ago)
- Last Synced: 2025-05-06T02:41:25.421Z (about 1 month ago)
- Topics: embed, inline, macro, proc-macro, procmacro, rust
- Language: Rust
- Homepage: https://docs.rs/inline-rust/
- Size: 8.79 KB
- Stars: 30
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://crates.io/crates/inline-rust)
[](https://docs.rs/inline-rust/)
[](https://github.com/WilliamVenner/inline-rust/blob/master/LICENSE)# inline-rust
This is a stupid macro inspired by [`inline-python`](https://github.com/fusion-engineering/inline-python) that compiles and executes Rust and spits the output directly into your Rust code.
There is a use case of using it to evaluate advanced "const" expressions, see the example below... if you dare.
# Usage
```toml
[dependencies]
inline-rust = "*"
```# Example
```rust
// Compiles using cargo
const CONST_HASH: &'static str = inline_rust!(
r#"
[dependencies]
sha2 = "0.9.8"
"#,
{
use sha2::Digest;let mut sum: i32 = 0;
for n in 0..30 {
sum += n;
}format!("\"{:x}\"", sha2::Sha256::digest(&sum.to_ne_bytes()))
}
);// Compiles using rustc
const CONST_FOR_LOOP: i32 = inline_rust!({
let mut sum: i32 = 0;
for n in 0..30 {
sum += n;
}
format!("{}", sum)
});
```