Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ rust:
sudo: false
env:
matrix:
- FEATURES=
- FEATURES=""
- FEATURES="std"
- FEATURES="serde"
- FEATURES="std,serde"
script:
- cargo test -v --features "$FEATURES"
- cargo test -v --no-default-features --features "$FEATURES"
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ license = "MIT"
description = "Wrappers for total ordering on floats"
repository = "https://github.com/reem/rust-ordered-float"
readme = "README.md"
keywords = ["no_std", "ord", "f64", "f32", "sort"]
categories = ["science", "rust-patterns", "no-std"]

[dependencies]
num-traits = "0.2"
serde = { version = "1.0", optional = true }
serde = { version = "1.0", optional = true, default-features = false }

[dev-dependencies]
serde_test = "1.0"

[features]
default = ["std"]
std = []
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ ordered-float = "1.0"

See the [API documentation](https://docs.rs/ordered-float) for further details.

## no_std

To use `ordered_float` without requiring the Rust standard library, disable
the default `std` feature:

```toml
[dependencies]
ordered-float = { version = "1.0", default-features = false }
```

## License

MIT
31 changes: 17 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#![no_std]
#![cfg_attr(test, deny(warnings))]
#![deny(missing_docs)]

//! Wrappers for total order on Floats.

extern crate num_traits;
#[cfg(feature = "std")] extern crate std;

use std::cmp::Ordering;
use std::error::Error;
use std::ops::{Add, AddAssign, Deref, DerefMut, Div, DivAssign, Mul, MulAssign, Neg, Rem,
use core::cmp::Ordering;
use core::ops::{Add, AddAssign, Deref, DerefMut, Div, DivAssign, Mul, MulAssign, Neg, Rem,
RemAssign, Sub, SubAssign};
use std::hash::{Hash, Hasher};
use std::fmt;
use std::io;
use std::mem;
use std::hint::unreachable_unchecked;
use core::hash::{Hash, Hasher};
use core::fmt;
use core::mem;
use core::hint::unreachable_unchecked;
use num_traits::{Bounded, Float, FromPrimitive, Num, NumCast, One, Signed, ToPrimitive,
Zero};

Expand Down Expand Up @@ -553,7 +553,8 @@ impl<T: Float> Neg for NotNan<T> {
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct FloatIsNan;

impl Error for FloatIsNan {
#[cfg(feature = "std")]
impl std::error::Error for FloatIsNan {
fn description(&self) -> &str {
"NotNan constructed with NaN"
}
Expand All @@ -565,9 +566,10 @@ impl fmt::Display for FloatIsNan {
}
}

impl Into<io::Error> for FloatIsNan {
fn into(self) -> io::Error {
io::Error::new(io::ErrorKind::InvalidInput, self)
#[cfg(feature = "std")]
impl Into<std::io::Error> for FloatIsNan {
fn into(self) -> std::io::Error {
std::io::Error::new(std::io::ErrorKind::InvalidInput, self)
}
}

Expand Down Expand Up @@ -653,7 +655,8 @@ pub enum ParseNotNanError<E> {
IsNaN,
}

impl<E: fmt::Debug> Error for ParseNotNanError<E> {
#[cfg(feature = "std")]
impl<E: fmt::Debug> std::error::Error for ParseNotNanError<E> {
fn description(&self) -> &str {
return "Error parsing a not-NaN floating point value";
}
Expand Down Expand Up @@ -700,7 +703,7 @@ mod impl_serde {
use self::serde::de::{Error, Unexpected};
use super::{OrderedFloat, NotNan};
use num_traits::Float;
use std::f64;
use core::f64;

#[cfg(test)]
extern crate serde_test;
Expand Down