From 956bb0f4db0312a56e87be155954697ace9cd325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jan=20Niemier?= Date: Fri, 25 Mar 2016 12:34:48 +0100 Subject: [PATCH] Reapply ebed6756de732f959bbc72bbb9ec8c4e28b19143 --- traits/src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/traits/src/lib.rs b/traits/src/lib.rs index 869b92f..366b1db 100644 --- a/traits/src/lib.rs +++ b/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); +}