Add support for 128-bit integers
Only compile in this support if rustc is new enough, otherwise continue
to omit the bindings for older-than-1.26 rustc
Closes #143
diff --git a/build.rs b/build.rs
index 30b5f05..3379da3 100644
--- a/build.rs
+++ b/build.rs
@@ -7,16 +7,20 @@
let target = env::var("TARGET").unwrap();
- if !enable_use_proc_macro(&target) {
- return;
- }
- println!("cargo:rustc-cfg=use_proc_macro");
-
let minor = match rustc_minor_version() {
Some(n) => n,
None => return,
};
+ if minor >= 26 {
+ println!("cargo:rustc-cfg=u128");
+ }
+
+ if !enable_use_proc_macro(&target) {
+ return;
+ }
+ println!("cargo:rustc-cfg=use_proc_macro");
+
// Rust 1.29 stabilized the necessary APIs in the `proc_macro` crate
if minor >= 29 || cfg!(feature = "nightly") {
println!("cargo:rustc-cfg=wrap_proc_macro");
diff --git a/src/lib.rs b/src/lib.rs
index ba9e67b..a26b117 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -973,6 +973,12 @@
isize_suffixed => isize,
}
+ #[cfg(u128)]
+ suffixed_int_literals! {
+ u128_suffixed => u128,
+ i128_suffixed => i128,
+ }
+
unsuffixed_int_literals! {
u8_unsuffixed => u8,
u16_unsuffixed => u16,
@@ -986,6 +992,12 @@
isize_unsuffixed => isize,
}
+ #[cfg(u128)]
+ unsuffixed_int_literals! {
+ u128_unsuffixed => u128,
+ i128_unsuffixed => i128,
+ }
+
pub fn f64_unsuffixed(f: f64) -> Literal {
assert!(f.is_finite());
Literal::_new(imp::Literal::f64_unsuffixed(f))
diff --git a/src/stable.rs b/src/stable.rs
index 6c06fc4..0d8aac9 100644
--- a/src/stable.rs
+++ b/src/stable.rs
@@ -678,6 +678,12 @@
f64_suffixed => f64,
}
+ #[cfg(u128)]
+ suffixed_numbers! {
+ u128_suffixed => u128,
+ i128_suffixed => i128,
+ }
+
unsuffixed_numbers! {
u8_unsuffixed => u8,
u16_unsuffixed => u16,
@@ -691,6 +697,12 @@
isize_unsuffixed => isize,
}
+ #[cfg(u128)]
+ unsuffixed_numbers! {
+ u128_unsuffixed => u128,
+ i128_unsuffixed => i128,
+ }
+
pub fn f32_unsuffixed(f: f32) -> Literal {
let mut s = f.to_string();
if !s.contains(".") {
diff --git a/src/unstable.rs b/src/unstable.rs
index 433639d..d15b9da 100644
--- a/src/unstable.rs
+++ b/src/unstable.rs
@@ -819,6 +819,12 @@
f64_suffixed => f64,
}
+ #[cfg(u128)]
+ suffixed_numbers! {
+ i128_suffixed => i128,
+ u128_suffixed => u128,
+ }
+
unsuffixed_integers! {
u8_unsuffixed => u8,
u16_unsuffixed => u16,
@@ -832,6 +838,12 @@
isize_unsuffixed => isize,
}
+ #[cfg(u128)]
+ unsuffixed_integers! {
+ i128_unsuffixed => i128,
+ u128_unsuffixed => u128,
+ }
+
pub fn f32_unsuffixed(f: f32) -> Literal {
if nightly_works() {
Literal::Nightly(proc_macro::Literal::f32_unsuffixed(f))