Skip to content

Commit 4e37c4f

Browse files
committed
add cfg the way num-bigint does it
1 parent eec17f4 commit 4e37c4f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,14 @@ fn main() {
44
println!("cargo:rustc-cfg=has_int_exp_fmt");
55
}
66

7+
let std = if ac.probe_sysroot_crate("std") {
8+
"std"
9+
} else {
10+
"core"
11+
};
12+
if ac.probe_path(&format!("{}::convert::TryFrom", std)) {
13+
autocfg::emit("has_try_from");
14+
}
15+
716
autocfg::rerun_path(file!());
817
}

src/from.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::convert::TryFrom;
44
macro_rules! impl_try_from {
55
( $($name:ty),* => $into:ty ; $approx:ident) => {
66
$(
7+
#[cfg(has_try_from)]
78
impl TryFrom<$name> for Ratio<$into> {
89
type Error = ();
910
paste::paste! {
@@ -16,13 +17,15 @@ macro_rules! impl_try_from {
1617
}
1718
)*
1819

20+
#[cfg(has_try_from)]
1921
impl TryFrom<f32> for Ratio<$into> {
2022
type Error = ();
2123
fn try_from(n: f32) -> Result<Self, ()> {
2224
$approx(n, 10e-20, 30).ok_or(())
2325
}
2426
}
2527

28+
#[cfg(has_try_from)]
2629
impl TryFrom<f64> for Ratio<$into> {
2730
type Error = ();
2831
fn try_from(n: f64) -> Result<Self, ()> {

0 commit comments

Comments
 (0)