impl Debug for ParseFloatError

Fixes #165.
This commit is contained in:
Josh Stone 2016-02-16 15:37:06 -08:00
parent 1a15d33560
commit ebed6756de
1 changed files with 20 additions and 6 deletions

View File

@ -43,14 +43,16 @@ macro_rules! int_trait_impl {
)*) )*)
} }
// FIXME: Temporary replacements for unstable ::std::num::ParseFloatError and // FIXME: std::num::ParseFloatError is stable in 1.0, but opaque to us,
// ::std::num::FloatErrorKind. These can be removed once the std float implementation of // so there's not really any way for us to reuse it.
// from_str_radix stabilises. #[derive(Debug)]
pub enum FloatErrorKind { Empty, Invalid }
pub struct ParseFloatError { pub kind: FloatErrorKind } 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 // FIXME: The standard library from_str_radix on floats was deprecated, so we're stuck
// it is stabilised. // 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 { macro_rules! float_trait_impl {
($name:ident for $($t:ty)*) => ($( ($name:ident for $($t:ty)*) => ($(
impl $name for $t { 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!(f32 integer_decode_f32);
float_impl!(f64 integer_decode_f64); 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);
}