Merge #22
22: Implement std::fmt::Display for ParseFloatError r=cuviper a=svartalf Basically it is a copy of the stdlib implementation, should close #2
This commit is contained in:
commit
9c8676e6d5
12
src/lib.rs
12
src/lib.rs
|
@ -15,6 +15,7 @@
|
|||
use std::ops::{Add, Sub, Mul, Div, Rem};
|
||||
use std::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
|
||||
use std::num::Wrapping;
|
||||
use std::fmt;
|
||||
|
||||
pub use bounds::Bounded;
|
||||
pub use float::{Float, FloatConst};
|
||||
|
@ -163,6 +164,17 @@ pub struct ParseFloatError {
|
|||
pub kind: FloatErrorKind,
|
||||
}
|
||||
|
||||
impl fmt::Display for ParseFloatError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let description = match self.kind {
|
||||
FloatErrorKind::Empty => "cannot parse float from empty string",
|
||||
FloatErrorKind::Invalid => "invalid float literal",
|
||||
};
|
||||
|
||||
description.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
|
Loading…
Reference in New Issue