Browse Source

Reapply ebed6756de732f959bbc72bbb9ec8c4e28b19143

Łukasz Jan Niemier 9 years ago
parent
commit
956bb0f4db
1 changed files with 18 additions and 0 deletions
  1. 18 0
      traits/src/lib.rs

+ 18 - 0
traits/src/lib.rs

@@ -54,14 +54,21 @@ macro_rules! int_trait_impl {
 }
 int_trait_impl!(Num for usize u8 u16 u32 u64 isize i8 i16 i32 i64);
 
+#[derive(Debug)]
 pub enum FloatErrorKind {
     Empty,
     Invalid,
 }
+// FIXME: std::num::ParseFloatError is stable in 1.0, but opaque to us,
+// so there's not really any way for us to reuse it.
+#[derive(Debug)]
 pub struct ParseFloatError {
     pub kind: FloatErrorKind,
 }
 
+// FIXME: The standard library from_str_radix on floats was deprecated, so we're stuck
+// with this implementation ourselves until we want to make a breaking change.
+// (would have to drop it from `Num` though)
 macro_rules! float_trait_impl {
     ($name:ident for $($t:ty)*) => ($(
         impl $name for $t {
@@ -213,3 +220,14 @@ macro_rules! float_trait_impl {
     )*)
 }
 float_trait_impl!(Num for f32 f64);
+
+#[test]
+fn from_str_radix_unwrap() {
+    // The Result error must impl Debug to allow unwrap()
+
+    let i: i32 = Num::from_str_radix("0", 10).unwrap();
+    assert_eq!(i, 0);
+
+    let f: f32 = Num::from_str_radix("0.0", 10).unwrap();
+    assert_eq!(f, 0.0);
+}