Skip to content

Commit 471af99

Browse files
authored
Merge pull request #51 from mbrubeck/no_std
no_std support
2 parents fd8107c + 0bcf90b commit 471af99

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ rust:
77
sudo: false
88
env:
99
matrix:
10-
- FEATURES=
10+
- FEATURES=""
11+
- FEATURES="std"
1112
- FEATURES="serde"
13+
- FEATURES="std,serde"
1214
script:
13-
- cargo test -v --features "$FEATURES"
15+
- cargo test -v --no-default-features --features "$FEATURES"

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ license = "MIT"
66
description = "Wrappers for total ordering on floats"
77
repository = "https://github.com/reem/rust-ordered-float"
88
readme = "README.md"
9+
keywords = ["no_std", "ord", "f64", "f32", "sort"]
10+
categories = ["science", "rust-patterns", "no-std"]
911

1012
[dependencies]
1113
num-traits = "0.2"
12-
serde = { version = "1.0", optional = true }
14+
serde = { version = "1.0", optional = true, default-features = false }
1315

1416
[dev-dependencies]
1517
serde_test = "1.0"
18+
19+
[features]
20+
default = ["std"]
21+
std = []

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ ordered-float = "1.0"
1414

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

17+
## no_std
18+
19+
To use `ordered_float` without requiring the Rust standard library, disable
20+
the default `std` feature:
21+
22+
```toml
23+
[dependencies]
24+
ordered-float = { version = "1.0", default-features = false }
25+
```
26+
1727
## License
1828

1929
MIT

src/lib.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
#![no_std]
12
#![cfg_attr(test, deny(warnings))]
23
#![deny(missing_docs)]
34

45
//! Wrappers for total order on Floats.
56
67
extern crate num_traits;
8+
#[cfg(feature = "std")] extern crate std;
79

8-
use std::cmp::Ordering;
9-
use std::error::Error;
10-
use std::ops::{Add, AddAssign, Deref, DerefMut, Div, DivAssign, Mul, MulAssign, Neg, Rem,
10+
use core::cmp::Ordering;
11+
use core::ops::{Add, AddAssign, Deref, DerefMut, Div, DivAssign, Mul, MulAssign, Neg, Rem,
1112
RemAssign, Sub, SubAssign};
12-
use std::hash::{Hash, Hasher};
13-
use std::fmt;
14-
use std::io;
15-
use std::mem;
16-
use std::hint::unreachable_unchecked;
13+
use core::hash::{Hash, Hasher};
14+
use core::fmt;
15+
use core::mem;
16+
use core::hint::unreachable_unchecked;
1717
use num_traits::{Bounded, Float, FromPrimitive, Num, NumCast, One, Signed, ToPrimitive,
1818
Zero};
1919

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

556-
impl Error for FloatIsNan {
556+
#[cfg(feature = "std")]
557+
impl std::error::Error for FloatIsNan {
557558
fn description(&self) -> &str {
558559
"NotNan constructed with NaN"
559560
}
@@ -565,9 +566,10 @@ impl fmt::Display for FloatIsNan {
565566
}
566567
}
567568

568-
impl Into<io::Error> for FloatIsNan {
569-
fn into(self) -> io::Error {
570-
io::Error::new(io::ErrorKind::InvalidInput, self)
569+
#[cfg(feature = "std")]
570+
impl Into<std::io::Error> for FloatIsNan {
571+
fn into(self) -> std::io::Error {
572+
std::io::Error::new(std::io::ErrorKind::InvalidInput, self)
571573
}
572574
}
573575

@@ -653,7 +655,8 @@ pub enum ParseNotNanError<E> {
653655
IsNaN,
654656
}
655657

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

705708
#[cfg(test)]
706709
extern crate serde_test;

0 commit comments

Comments
 (0)