Crate extprim_literals [−] [src]
Literal macros for extprim.
This crate provides a compiler plugin (on nightly) or syntex extension (on stable) so that the
extprim types can be constructed at compile-time using the i128!() and u128!() macros.
Setup as compiler plugin (nightly)
Add extprim_literals to the dev-dependencies in Cargo.toml:
[dev-dependencies]
extprim_literals = "1.0.0"
Then just use the plugin:
#![feature(plugin)] #![plugin(extprim_literals)] use extprim::u128::u128; const TEN: u128 = u128!(10);
Setup as syntex extension (stable)
Supply a build.rs, and add syntex and extprim_literals to the build-dependencies in
Cargo.toml:
[package]
build = "build.rs"
[build-dependencies]
extprim_literals = "1.0.0"
syntex = "0.31.0"
Register extprim_literals to syntex in build.rs:
extern crate syntex; extern crate extprim_literals; use syntex::Registry; use std::env; use std::path::Path; fn main() { let mut registry = Registry::new(); extprim_literals::register(&mut registry); let src = Path::new("src/consts.rs.in"); let dst = Path::new(&env::var("OUT_DIR").unwrap()).join("consts.rs"); registry.expand("extprim_literals", &src, &dst).unwrap(); }
Use the macros in src/consts.rs.in:
use extprim::u128::u128; const TEN: u128 = u128!(10);
Include the expanded file in src/consts.rs:
include!(concat!(env!("OUT_DIR"), "/consts.rs"));
Macros
| i128! |
Creates a signed 128-bit integer at compile time. The content can be any integer literals supported by Rust, e.g. |
| u128! |
Creates an unsigned 128-bit integer at compile time. The content can be any integer literals supported by Rust, e.g. |
Functions
| register |
Register the |