Repository: brendanzab/approx (language: rust)

Issue:
Compilation with no_std fails.
Enabling the `no_std` feature does not compile because of the use of an unstable library feature:

```rust
error[E0658]: use of unstable library feature 'float_internals': internal routines only exposed for testing
 --> src/abs_diff_eq.rs:7:5
  |
7 | use core::num::Float;
  |     ^^^^^^^^^^^^^^^^
  |
  = help: add #![feature(float_internals)] to the crate attributes to enable

error[E0658]: use of unstable library feature 'float_internals': internal routines only exposed for testing
 --> src/relative_eq.rs:7:5
  |
7 | use core::num::Float;
  |     ^^^^^^^^^^^^^^^^
  |
  = help: add #![feature(float_internals)] to the crate attributes to enable

error[E0658]: use of unstable library feature 'float_internals': internal routines only exposed for testing
 --> src/ulps_eq.rs:5:5
  |
5 | use core::num::Float;
  |     ^^^^^^^^^^^^^^^^
  |
  = help: add #![feature(float_internals)] to the crate attributes to enable
```

Instead, I suggest:
* Depending on `num-traits` in order to use their `FloatCore` trait instead of `core::num::Float`.
* Making the activation of `#![no_std]` more idiomatic. Usually, we define a `std` feature that is enabled by default on the `Cargo.toml`. To activate the `#![no_std]` attribute, one has to depend on `approx` with `no_default_features`.


Discussion / hints:

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 16c99a5..2a21a05 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,8 +26,10 @@ keywords = [
 name = "approx"
 
 [features]
-no_std = []
+default = [ "std" ]
+std = []
 use_complex = ["num-complex"]
 
 [dependencies]
+num-traits = { version = "0.2.0", default_features = false }
 num-complex = { version = "0.1.37", optional = true }
diff --git a/src/abs_diff_eq.rs b/src/abs_diff_eq.rs
index f5753a4..2998d26 100644
--- a/src/abs_diff_eq.rs
+++ b/src/abs_diff_eq.rs
@@ -1,10 +1,5 @@
-#[cfg(feature="no_std")]
-use core::{cell, f32, f64};
-#[cfg(not(feature="no_std"))]
 use std::{cell, f32, f64};
-#[cfg(feature="no_std")]
-#[cfg_attr(feature="no_std", allow(unused_imports))] // HACK: seems to be a bug in this lint!
-use core::num::Float;
+use num_traits::float::FloatCore;
 #[cfg(feature="use_complex")]
 use num_complex::Complex;
 
diff --git a/src/lib.rs b/src/lib.rs
index 97391da..aa29177 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -154,12 +154,15 @@
 //! - [What Every Computer Scientist Should Know About Floating-Point Arithmetic]
 //!   (https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)
 
-#![cfg_attr(feature="no_std", no_std)]
-#![cfg_attr(feature="no_std", feature(core_float))]
+#![cfg_attr(not(feature = "std"), no_std)]
 
+extern crate num_traits;
 #[cfg(feature="use_complex")]
 extern crate num_complex;
 
+#[cfg(not(feature = "std"))]
+use core as std;
+
 mod abs_diff_eq;
 mod relative_eq;
 mod ulps_eq;
diff --git a/src/relative_eq.rs b/src/relative_eq.rs
index a19bf4b..e39b184 100644
--- a/src/relative_eq.rs
+++ b/src/relative_eq.rs
@@ -1,10 +1,5 @@
-#[cfg(feature="no_std")]
-use core::{cell, f32, f64};
-#[cfg(not(feature="no_std"))]
 use std::{cell, f32, f64};
-#[cfg(feature="no_std")]
-#[cfg_attr(feature="no_std", allow(unused_imports))] // HACK: seems to be a bug in this lint!
-use core::num::Float;
+use num_traits::float::FloatCore;
 #[cfg(feature="use_complex")]
 use num_complex::Complex;
 
diff --git a/src/ulps_eq.rs b/src/ulps_eq.rs
index a3abf4b..1f64707 100644
--- a/src/ulps_eq.rs
+++ b/src/ulps_eq.rs
@@ -1,10 +1,5 @@
-#[cfg(feature="no_std")]
-use core::{cell, mem};
-#[cfg(feature="no_std")]
-#[cfg_attr(feature="no_std", allow(unused_imports))] // HACK: seems to be a bug in this lint!
-use core::num::Float;
-#[cfg(not(feature="no_std"))]
 use std::{cell, mem};
+use num_traits::float::FloatCore;
 #[cfg(feature="use_complex")]
 use num_complex::Complex;
 


Test patch: