Skip to content

Commit 39f76bb

Browse files
committed
Replace From<T> with TryFrom<T> for NotNan<T>
Fixes #56. Fixes #57.
1 parent fc9dc0c commit 39f76bb

File tree

3 files changed

+139
-128
lines changed

3 files changed

+139
-128
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: rust
22
rust:
3-
- 1.28.0
3+
- 1.34.0
44
- nightly
55
- beta
66
- stable

src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern crate num_traits;
88
#[cfg(feature = "std")] extern crate std;
99

1010
use core::cmp::Ordering;
11+
use core::convert::TryFrom;
1112
use core::ops::{Add, AddAssign, Deref, DerefMut, Div, DivAssign, Mul, MulAssign, Neg, Rem,
1213
RemAssign, Sub, SubAssign};
1314
use core::hash::{Hash, Hasher};
@@ -300,12 +301,17 @@ impl From<NotNan<f64>> for f64 {
300301
}
301302
}
302303

303-
/// Creates a NotNan value from a Float.
304-
///
305-
/// Panics if the provided value is NaN or the computation results in NaN
306-
impl<T: Float> From<T> for NotNan<T> {
307-
fn from(v: T) -> Self {
308-
NotNan::new(v).expect("Tried to create a NotNan from a NaN")
304+
impl TryFrom<f32> for NotNan<f32> {
305+
type Error = FloatIsNan;
306+
fn try_from(v: f32) -> Result<Self, Self::Error> {
307+
NotNan::new(v)
308+
}
309+
}
310+
311+
impl TryFrom<f64> for NotNan<f64> {
312+
type Error = FloatIsNan;
313+
fn try_from(v: f64) -> Result<Self, Self::Error> {
314+
NotNan::new(v)
309315
}
310316
}
311317

0 commit comments

Comments
 (0)