From ebed6756de732f959bbc72bbb9ec8c4e28b19143 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 16 Feb 2016 15:37:06 -0800 Subject: [PATCH] impl Debug for ParseFloatError Fixes #165. --- src/traits.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index 5b01b39..a4205d7 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -43,14 +43,16 @@ macro_rules! int_trait_impl { )*) } -// FIXME: Temporary replacements for unstable ::std::num::ParseFloatError and -// ::std::num::FloatErrorKind. These can be removed once the std float implementation of -// from_str_radix stabilises. -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 } +#[derive(Debug)] +pub enum FloatErrorKind { Empty, Invalid } -// FIXME: This should be removed and replaced with the std implementation of from_str_radix once -// it is stabilised. +// 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 { @@ -2536,3 +2538,15 @@ fn integer_decode_f64(f: f64) -> (u64, i16, i8) { float_impl!(f32 integer_decode_f32); float_impl!(f64 integer_decode_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); +}