Crate extprim_literals [−] [src]
Literal macros for extprim
.
This crate provides a syntex extension (on stable) so that the extprim
types can be
constructed at compile-time using the i128!()
and u128!()
macros.
Since built-in u128/i128 types are provided on nightly (Rust 1.16), the i128!()
and u128!()
macros will simply cast the input from these built-in types.
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.2.0"
syntex = "0.48.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
:
#[macro_use] extern crate extprim_literals; 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 |