Crates.io | syntex |
lib.rs | syntex |
version | 0.58.1 |
source | src |
created_at | 2014-12-05 20:21:07.600281 |
updated_at | 2017-02-19 21:22:23.251257 |
description | A library that enables compile time syntax extension expansion |
homepage | |
repository | https://github.com/erickt/rust-syntex |
max_upload_size | |
id | 464 |
size | 26,972 |
syntex
is a library that enables compile time syntax extension expansion.
This allows users to use libraries like serde
on stable Rust.
To create a package:
[package]
name = "hello_world_macros"
version = "0.2.0"
authors = [ "erick.tryzelaar@gmail.com" ]
[dependencies]
syntex = "*"
syntex_syntax = "*"
To use it:
Cargo.toml:
[package]
name = "hello_world"
version = "0.3.0"
authors = [ "erick.tryzelaar@gmail.com" ]
build = "build.rs"
[build-dependencies]
syntex = "*"
build.rs:
extern crate syntex;
extern crate hello_world_macros;
use std::env;
use std::path::Path;
fn main() {
let mut registry = syntex::Registry::new();
hello_world_macros::register(&mut registry);
let src = Path::new("src/main.rs.in");
let dst = Path::new(&env::var("OUT_DIR").unwrap()).join("main.rs");
registry.expand("hello_world", &src, &dst).unwrap();
}
src/main.rs:
// Include the real main
include!(concat!(env!("OUT_DIR"), "/main.rs"));
src/main.rs.in:
fn main() {
let s = hello_world!();
println!("{}", s);
}
Unfortunately because there is no stable plugin support in Rust yet, there are some things that syntex cannot do:
vec![]
, println!(...)
, and etc. This is because those macros
may override the macro_name!(...)
to mean something different.