зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1500259 - update rkv to 0.5 and uuid to 0.6 r=froydnj
Updating rkv to 0.5 enables us to un-vendor new-ordered-float, as rkv 0.4 is the last crate in the tree that depends on it. It also enables us to un-vendor version 0.5 of uuid. We previously needed that version because multiple third-party crates depended on it, and we have limited control over third-party sub-dependencies. But rkv 0.4 was the last third-party crate that still depended on version 0.5 of uuid; rkv 0.5 depends on version 0.6 of uuid. There would still be two internal crates that depend on version 0.5 of uuid: geckodriver and webrender_bindings. But we have more control over internal sub-dependencies, and we can update those two internal crates to depend on version 0.6 of uuid. This patch does so. To summarize, this patch makes the following changes: * rkv: 0.4 -> 0.5 * new-ordered-float: un-vendored * geckodriver: uuid dependency 0.5 -> 0.6 * webrender_bindings: uuid dependency 0.5 -> 0.6 * uuid 0.5: un-vendored * uuid 0.6: remains in tree Differential Revision: https://phabricator.services.mozilla.com/D9160 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
57fb53bfa2
Коммит
898ee70419
|
@ -974,7 +974,7 @@ dependencies = [
|
|||
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.66 (git+https://github.com/servo/serde?branch=deserialize_from_enums8)",
|
||||
"serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uuid 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"webdriver 0.38.0",
|
||||
"zip 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -1049,7 +1049,7 @@ dependencies = [
|
|||
"nsstring 0.1.0",
|
||||
"prefs_parser 0.0.1",
|
||||
"profiler_helper 0.1.0",
|
||||
"rkv 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rkv 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rsdparsa_capi 0.1.0",
|
||||
"rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"u2fhid 0.2.2",
|
||||
|
@ -1658,15 +1658,6 @@ dependencies = [
|
|||
"nsstring 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "new-ordered-float"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "new_debug_unreachable"
|
||||
version = "1.0.1"
|
||||
|
@ -2064,7 +2055,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rkv"
|
||||
version = "0.4.1"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"arrayref 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2072,10 +2063,10 @@ dependencies = [
|
|||
"failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lmdb-rkv 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"new-ordered-float 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ordered-float 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uuid 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2851,20 +2842,13 @@ name = "utf8-ranges"
|
|||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3001,7 +2985,7 @@ dependencies = [
|
|||
"nsstring 0.1.0",
|
||||
"rayon 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thread_profiler 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uuid 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"webrender 0.57.2",
|
||||
]
|
||||
|
||||
|
@ -3273,7 +3257,6 @@ dependencies = [
|
|||
"checksum mp4parse_fallible 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6626c2aef76eb8f984eef02e475883d3fe9112e114720446c5810fc5f045cd30"
|
||||
"checksum msdos_time 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aad9dfe950c057b1bfe9c1f2aa51583a8468ef2a5baba2ebbe06d775efeb7729"
|
||||
"checksum net2 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)" = "9044faf1413a1057267be51b5afba8eb1090bd2231c693664aa1db716fe1eae0"
|
||||
"checksum new-ordered-float 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8ccbebba6fb53a6d2bdcfaf79cb339bc136dee3bfff54dc337a334bafe36476a"
|
||||
"checksum new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0cdc457076c78ab54d5e0d6fa7c47981757f1e34dc39ff92787f217dede586c4"
|
||||
"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
|
||||
"checksum nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05aec50c70fd288702bcd93284a8444607f3292dbdf2a30de5ea5dcdbe72287b"
|
||||
|
@ -3318,7 +3301,7 @@ dependencies = [
|
|||
"checksum regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75ecf88252dce580404a22444fc7d626c01815debba56a7f4f536772a5ff19d3"
|
||||
"checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db"
|
||||
"checksum regex-syntax 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f1ac0f60d675cc6cf13a20ec076568254472551051ad5dd050364d70671bf6b"
|
||||
"checksum rkv 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "21983ae9330b1e1cb1d01868229618a3c7cc5134955f0dc1a86a0a1886f3acb7"
|
||||
"checksum rkv 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "663e50c3b2454387726a83b01629892824dcf113c0471841ea4bc9b5929eb75e"
|
||||
"checksum ron 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "da06feaa07f69125ab9ddc769b11de29090122170b402547f64b86fe16ebc399"
|
||||
"checksum runloop 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d79b4b604167921892e84afbbaad9d5ad74e091bf6c511d9dbfb0593f09fabd"
|
||||
"checksum rust-ini 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8a654c5bda722c699be6b0fe4c0d90de218928da5b724c3e467fc48865c37263"
|
||||
|
@ -3394,7 +3377,6 @@ dependencies = [
|
|||
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
|
||||
"checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7"
|
||||
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
|
||||
"checksum uuid 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcc7e3b898aa6f6c08e5295b6c89258d1331e9ac578cc992fb818759951bdc22"
|
||||
"checksum uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e1436e58182935dcd9ce0add9ea0b558e8a87befe01c1a301e6020aeb0876363"
|
||||
"checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b"
|
||||
"checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c"
|
||||
|
|
|
@ -13,7 +13,7 @@ gleam = "0.6.3"
|
|||
log = "0.4"
|
||||
nsstring = { path = "../../servo/support/gecko/nsstring" }
|
||||
bincode = "1.0"
|
||||
uuid = { version = "0.5", features = ["v4"] }
|
||||
uuid = { version = "0.6", features = ["v4"] }
|
||||
fxhash = "0.2.1"
|
||||
|
||||
[dependencies.webrender]
|
||||
|
|
|
@ -22,7 +22,7 @@ regex = "1.0"
|
|||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde_derive = "1.0"
|
||||
uuid = { version = "0.5", features = ["v4"] }
|
||||
uuid = { version = "0.6", features = ["v4"] }
|
||||
webdriver = { path = "../webdriver" }
|
||||
zip = "0.4"
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
{"files":{".travis.yml":"b828951788f67d00e3869f32b15076dcd8b64d71889c9dacda339571d7da93ac","Cargo.toml":"b2d65471546d2c240fcc7522e68967a5ec9d13bf829dffd708a55739ef337a28","LICENSE-MIT":"f7715d38a3fa1b4ac97c5729740752505a39cb92ee83ab5b102aeb5eaa7cdea4","README.md":"53364727f8bdc8dac2f5a55e7b9741981b757ba5b9331e3ac8ed433b09ee2409","src/lib.rs":"a1fd03bd7601b842b60a94c6161c436befaf25b38f74b247a20e90c24fb2bd9f","tests/test.rs":"1bbfc79ee6e1ffa3fcc384e9ce1f5a9000a63a8ddbc84264caba0454d657f40a","tests/test_deprecated_names.rs":"6f661c27e8b4d625c02202895f220d573e3dccc8cf684c77e754c444403939f7"},"package":"8ccbebba6fb53a6d2bdcfaf79cb339bc136dee3bfff54dc337a334bafe36476a"}
|
|
@ -1,9 +0,0 @@
|
|||
language: rust
|
||||
rust: nightly
|
||||
sudo: false
|
||||
env:
|
||||
matrix:
|
||||
- FEATURES=
|
||||
- FEATURES="serde"
|
||||
script:
|
||||
- cargo test -v --features "$FEATURES"
|
|
@ -1,34 +0,0 @@
|
|||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g. crates.io) dependencies
|
||||
#
|
||||
# If you believe there's an error in this file please file an
|
||||
# issue against the rust-lang/cargo repository. If you're
|
||||
# editing this file be aware that the upstream Cargo.toml
|
||||
# will likely look very different (and much more reasonable)
|
||||
|
||||
[package]
|
||||
name = "new-ordered-float"
|
||||
version = "1.0.1"
|
||||
authors = ["Jonathan Reem <jonathan.reem@gmail.com>", "Matt Brubeck <mbrubeck@limpet.net>"]
|
||||
description = "Wrappers for total ordering on floats (fork of ordered-float)"
|
||||
readme = "README.md"
|
||||
license = "MIT"
|
||||
repository = "https://github.com/mbrubeck/rust-ordered-float"
|
||||
|
||||
[lib]
|
||||
name = "ordered_float"
|
||||
[dependencies.num-traits]
|
||||
version = "0.2"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
|
||||
[dependencies.unreachable]
|
||||
version = "1"
|
||||
[dev-dependencies.serde_test]
|
||||
version = "1.0"
|
|
@ -1,25 +0,0 @@
|
|||
Copyright (c) 2015 Jonathan Reem
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
|
@ -1,27 +0,0 @@
|
|||
# Ordered Floats
|
||||
|
||||
Provides several wrapper types for Ord and Eq implementations on f64.
|
||||
|
||||
This is a fork of https://crates.io/crates/ordered-float
|
||||
|
||||
## Usage
|
||||
|
||||
Use the crates.io repository; add this to your `Cargo.toml` along
|
||||
with the rest of your dependencies:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
new-ordered-float = "1.0"
|
||||
```
|
||||
|
||||
In your Rust code, the library name is still `ordered_float`:
|
||||
|
||||
```rust
|
||||
extern crate ordered_float;
|
||||
```
|
||||
|
||||
See the [API documentation](https://docs.rs/new-ordered-float) for further details.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
|
@ -1,741 +0,0 @@
|
|||
#![cfg_attr(test, deny(warnings))]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
//! Wrappers for total order on Floats.
|
||||
|
||||
extern crate num_traits;
|
||||
extern crate unreachable;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::error::Error;
|
||||
use std::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 unreachable::unreachable;
|
||||
use num_traits::{Bounded, Float, FromPrimitive, Num, NumCast, One, Signed, ToPrimitive,
|
||||
Zero};
|
||||
|
||||
/// A wrapper around Floats providing an implementation of Ord and Hash.
|
||||
///
|
||||
/// A NaN value cannot be stored in this type.
|
||||
#[deprecated(since = "0.6.0", note = "renamed to `NotNan`")]
|
||||
pub type NotNaN<T> = NotNan<T>;
|
||||
|
||||
/// An error indicating an attempt to construct NotNan from a NaN
|
||||
#[deprecated(since = "0.6.0", note = "renamed to `FloatIsNan`")]
|
||||
pub type FloatIsNaN = FloatIsNan;
|
||||
|
||||
// masks for the parts of the IEEE 754 float
|
||||
const SIGN_MASK: u64 = 0x8000000000000000u64;
|
||||
const EXP_MASK: u64 = 0x7ff0000000000000u64;
|
||||
const MAN_MASK: u64 = 0x000fffffffffffffu64;
|
||||
|
||||
// canonical raw bit patterns (for hashing)
|
||||
const CANONICAL_NAN_BITS: u64 = 0x7ff8000000000000u64;
|
||||
const CANONICAL_ZERO_BITS: u64 = 0x0u64;
|
||||
|
||||
/// A wrapper around Floats providing an implementation of Ord and Hash.
|
||||
///
|
||||
/// NaN is sorted as *greater* than all other values and *equal*
|
||||
/// to itself, in contradiction with the IEEE standard.
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
pub struct OrderedFloat<T: Float>(pub T);
|
||||
|
||||
impl<T: Float> OrderedFloat<T> {
|
||||
/// Get the value out.
|
||||
pub fn into_inner(self) -> T {
|
||||
let OrderedFloat(val) = self;
|
||||
val
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> AsRef<T> for OrderedFloat<T> {
|
||||
fn as_ref(&self) -> &T {
|
||||
let OrderedFloat(ref val) = *self;
|
||||
val
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> AsMut<T> for OrderedFloat<T> {
|
||||
fn as_mut(&mut self) -> &mut T {
|
||||
let OrderedFloat(ref mut val) = *self;
|
||||
val
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> PartialOrd for OrderedFloat<T> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> Ord for OrderedFloat<T> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
let lhs = self.as_ref();
|
||||
let rhs = other.as_ref();
|
||||
match lhs.partial_cmp(&rhs) {
|
||||
Some(ordering) => ordering,
|
||||
None => {
|
||||
if lhs.is_nan() {
|
||||
if rhs.is_nan() {
|
||||
Ordering::Equal
|
||||
} else {
|
||||
Ordering::Greater
|
||||
}
|
||||
} else {
|
||||
Ordering::Less
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float + PartialEq> PartialEq for OrderedFloat<T> {
|
||||
fn eq(&self, other: &OrderedFloat<T>) -> bool {
|
||||
if self.as_ref().is_nan() {
|
||||
other.as_ref().is_nan()
|
||||
} else if other.as_ref().is_nan() {
|
||||
false
|
||||
} else {
|
||||
self.as_ref() == other.as_ref()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> Hash for OrderedFloat<T> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
if self.is_nan() {
|
||||
// normalize to one representation of NaN
|
||||
hash_float(&T::nan(), state)
|
||||
} else {
|
||||
hash_float(self.as_ref(), state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float + fmt::Display> fmt::Display for OrderedFloat<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.as_ref().fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<f32> for OrderedFloat<f32> {
|
||||
fn into(self) -> f32 {
|
||||
self.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<f64> for OrderedFloat<f64> {
|
||||
fn into(self) -> f64 {
|
||||
self.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> From<T> for OrderedFloat<T> {
|
||||
fn from(val: T) -> Self {
|
||||
OrderedFloat(val)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> Deref for OrderedFloat<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> DerefMut for OrderedFloat<T> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
self.as_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float + PartialEq> Eq for OrderedFloat<T> {}
|
||||
|
||||
/// A wrapper around Floats providing an implementation of Ord and Hash.
|
||||
///
|
||||
/// A NaN value cannot be stored in this type.
|
||||
#[derive(PartialOrd, PartialEq, Debug, Default, Clone, Copy)]
|
||||
pub struct NotNan<T: Float>(T);
|
||||
|
||||
impl<T: Float> NotNan<T> {
|
||||
/// Create a NotNan value.
|
||||
///
|
||||
/// Returns Err if val is NaN
|
||||
pub fn new(val: T) -> Result<Self, FloatIsNan> {
|
||||
match val {
|
||||
ref val if val.is_nan() => Err(FloatIsNan),
|
||||
val => Ok(NotNan(val)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a NotNan value from a value that is guaranteed to not be NaN
|
||||
///
|
||||
/// Behaviour is undefined if `val` is NaN
|
||||
pub unsafe fn unchecked_new(val: T) -> Self {
|
||||
debug_assert!(!val.is_nan());
|
||||
NotNan(val)
|
||||
}
|
||||
|
||||
/// Get the value out.
|
||||
pub fn into_inner(self) -> T {
|
||||
let NotNan(val) = self;
|
||||
val
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> AsRef<T> for NotNan<T> {
|
||||
fn as_ref(&self) -> &T {
|
||||
let NotNan(ref val) = *self;
|
||||
val
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> Ord for NotNan<T> {
|
||||
fn cmp(&self, other: &NotNan<T>) -> Ordering {
|
||||
match self.partial_cmp(&other) {
|
||||
Some(ord) => ord,
|
||||
None => unsafe { unreachable() },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> Hash for NotNan<T> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
hash_float(self.as_ref(), state)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float + fmt::Display> fmt::Display for NotNan<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.as_ref().fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<f32> for NotNan<f32> {
|
||||
fn into(self) -> f32 {
|
||||
self.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<f64> for NotNan<f64> {
|
||||
fn into(self) -> f64 {
|
||||
self.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a NotNan value from a Float.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl<T: Float> From<T> for NotNan<T> {
|
||||
fn from(v: T) -> Self {
|
||||
assert!(!v.is_nan());
|
||||
NotNan(v)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> Deref for NotNan<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float + PartialEq> Eq for NotNan<T> {}
|
||||
|
||||
impl<T: Float> Add for NotNan<T> {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, other: Self) -> Self {
|
||||
NotNan(self.0 + other.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl<T: Float> Add<T> for NotNan<T> {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, other: T) -> Self {
|
||||
assert!(!other.is_nan());
|
||||
NotNan::new(self.0 + other).expect("Addition resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for NotNan<f64> {
|
||||
fn add_assign(&mut self, other: Self) {
|
||||
self.0 += other.0;
|
||||
assert!(!self.0.is_nan(), "Addition resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for NotNan<f32> {
|
||||
fn add_assign(&mut self, other: Self) {
|
||||
self.0 += other.0;
|
||||
assert!(!self.0.is_nan(), "Addition resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl AddAssign<f64> for NotNan<f64> {
|
||||
fn add_assign(&mut self, other: f64) {
|
||||
assert!(!other.is_nan());
|
||||
self.0 += other;
|
||||
assert!(!self.0.is_nan(), "Addition resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN.
|
||||
impl AddAssign<f32> for NotNan<f32> {
|
||||
fn add_assign(&mut self, other: f32) {
|
||||
assert!(!other.is_nan());
|
||||
self.0 += other;
|
||||
assert!(!self.0.is_nan(), "Addition resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> Sub for NotNan<T> {
|
||||
type Output = Self;
|
||||
|
||||
fn sub(self, other: Self) -> Self {
|
||||
NotNan::new(self.0 - other.0).expect("Subtraction resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// Subtracts a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl<T: Float> Sub<T> for NotNan<T> {
|
||||
type Output = Self;
|
||||
|
||||
fn sub(self, other: T) -> Self {
|
||||
assert!(!other.is_nan());
|
||||
NotNan::new(self.0 - other).expect("Subtraction resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl SubAssign for NotNan<f64> {
|
||||
fn sub_assign(&mut self, other: Self) {
|
||||
self.0 -= other.0;
|
||||
assert!(!self.0.is_nan(), "Subtraction resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl SubAssign for NotNan<f32> {
|
||||
fn sub_assign(&mut self, other: Self) {
|
||||
self.0 -= other.0;
|
||||
assert!(!self.0.is_nan(), "Subtraction resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// Subtracts a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl SubAssign<f64> for NotNan<f64> {
|
||||
fn sub_assign(&mut self, other: f64) {
|
||||
assert!(!other.is_nan());
|
||||
self.0 -= other;
|
||||
assert!(!self.0.is_nan(), "Subtraction resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// Subtracts a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl SubAssign<f32> for NotNan<f32> {
|
||||
fn sub_assign(&mut self, other: f32) {
|
||||
assert!(!other.is_nan());
|
||||
self.0 -= other;
|
||||
assert!(!self.0.is_nan(), "Subtraction resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> Mul for NotNan<T> {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, other: Self) -> Self {
|
||||
NotNan::new(self.0 * other.0).expect("Multiplication resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// Multiplies a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl<T: Float> Mul<T> for NotNan<T> {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, other: T) -> Self {
|
||||
assert!(!other.is_nan());
|
||||
NotNan::new(self.0 * other).expect("Multiplication resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl MulAssign for NotNan<f64> {
|
||||
fn mul_assign(&mut self, other: Self) {
|
||||
self.0 *= other.0;
|
||||
assert!(!self.0.is_nan(), "Multiplication resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl MulAssign for NotNan<f32> {
|
||||
fn mul_assign(&mut self, other: Self) {
|
||||
self.0 *= other.0;
|
||||
assert!(!self.0.is_nan(), "Multiplication resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// Multiplies a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN.
|
||||
impl MulAssign<f64> for NotNan<f64> {
|
||||
fn mul_assign(&mut self, other: f64) {
|
||||
assert!(!other.is_nan());
|
||||
self.0 *= other;
|
||||
}
|
||||
}
|
||||
|
||||
/// Multiplies a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl MulAssign<f32> for NotNan<f32> {
|
||||
fn mul_assign(&mut self, other: f32) {
|
||||
assert!(!other.is_nan());
|
||||
self.0 *= other;
|
||||
assert!(!self.0.is_nan(), "Multiplication resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> Div for NotNan<T> {
|
||||
type Output = Self;
|
||||
|
||||
fn div(self, other: Self) -> Self {
|
||||
NotNan::new(self.0 / other.0).expect("Division resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// Divides a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl<T: Float> Div<T> for NotNan<T> {
|
||||
type Output = Self;
|
||||
|
||||
fn div(self, other: T) -> Self {
|
||||
assert!(!other.is_nan());
|
||||
NotNan::new(self.0 / other).expect("Division resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl DivAssign for NotNan<f64> {
|
||||
fn div_assign(&mut self, other: Self) {
|
||||
self.0 /= other.0;
|
||||
assert!(!self.0.is_nan(), "Division resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl DivAssign for NotNan<f32> {
|
||||
fn div_assign(&mut self, other: Self) {
|
||||
self.0 /= other.0;
|
||||
assert!(!self.0.is_nan(), "Division resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// Divides a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl DivAssign<f64> for NotNan<f64> {
|
||||
fn div_assign(&mut self, other: f64) {
|
||||
assert!(!other.is_nan());
|
||||
self.0 /= other;
|
||||
assert!(!self.0.is_nan(), "Division resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// Divides a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl DivAssign<f32> for NotNan<f32> {
|
||||
fn div_assign(&mut self, other: f32) {
|
||||
assert!(!other.is_nan());
|
||||
self.0 /= other;
|
||||
assert!(!self.0.is_nan(), "Division resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> Rem for NotNan<T> {
|
||||
type Output = Self;
|
||||
|
||||
fn rem(self, other: Self) -> Self {
|
||||
NotNan::new(self.0 % other.0).expect("Rem resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculates `%` with a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl<T: Float> Rem<T> for NotNan<T> {
|
||||
type Output = Self;
|
||||
|
||||
fn rem(self, other: T) -> Self {
|
||||
assert!(!other.is_nan());
|
||||
NotNan::new(self.0 % other).expect("Rem resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl RemAssign for NotNan<f64> {
|
||||
fn rem_assign(&mut self, other: Self) {
|
||||
self.0 %= other.0;
|
||||
assert!(!self.0.is_nan(), "Rem resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl RemAssign for NotNan<f32> {
|
||||
fn rem_assign(&mut self, other: Self) {
|
||||
self.0 %= other.0;
|
||||
assert!(!self.0.is_nan(), "Rem resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculates `%=` with a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl RemAssign<f64> for NotNan<f64> {
|
||||
fn rem_assign(&mut self, other: f64) {
|
||||
assert!(!other.is_nan());
|
||||
self.0 %= other;
|
||||
assert!(!self.0.is_nan(), "Rem resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculates `%=` with a float directly.
|
||||
///
|
||||
/// Panics if the provided value is NaN or the computation results in NaN
|
||||
impl RemAssign<f32> for NotNan<f32> {
|
||||
fn rem_assign(&mut self, other: f32) {
|
||||
assert!(!other.is_nan());
|
||||
self.0 %= other;
|
||||
assert!(!self.0.is_nan(), "Rem resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float> Neg for NotNan<T> {
|
||||
type Output = Self;
|
||||
|
||||
fn neg(self) -> Self {
|
||||
NotNan::new(-self.0).expect("Negation resulted in NaN")
|
||||
}
|
||||
}
|
||||
|
||||
/// An error indicating an attempt to construct NotNan from a NaN
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct FloatIsNan;
|
||||
|
||||
impl Error for FloatIsNan {
|
||||
fn description(&self) -> &str {
|
||||
"NotNan constructed with NaN"
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for FloatIsNan {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
<Self as fmt::Debug>::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<io::Error> for FloatIsNan {
|
||||
fn into(self) -> io::Error {
|
||||
io::Error::new(io::ErrorKind::InvalidInput, self)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn hash_float<F: Float, H: Hasher>(f: &F, state: &mut H) {
|
||||
raw_double_bits(f).hash(state);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn raw_double_bits<F: Float>(f: &F) -> u64 {
|
||||
if f.is_nan() {
|
||||
return CANONICAL_NAN_BITS;
|
||||
}
|
||||
|
||||
let (man, exp, sign) = f.integer_decode();
|
||||
if man == 0 {
|
||||
return CANONICAL_ZERO_BITS;
|
||||
}
|
||||
|
||||
let exp_u64 = unsafe { mem::transmute::<i16, u16>(exp) } as u64;
|
||||
let sign_u64 = if sign > 0 { 1u64 } else { 0u64 };
|
||||
(man & MAN_MASK) | ((exp_u64 << 52) & EXP_MASK) | ((sign_u64 << 63) & SIGN_MASK)
|
||||
}
|
||||
|
||||
impl<T: Float + Zero> Zero for NotNan<T> {
|
||||
fn zero() -> Self { NotNan(T::zero()) }
|
||||
|
||||
fn is_zero(&self) -> bool { self.0.is_zero() }
|
||||
}
|
||||
|
||||
impl<T: Float + One> One for NotNan<T> {
|
||||
fn one() -> Self { NotNan(T::one()) }
|
||||
}
|
||||
|
||||
impl<T: Float + Bounded> Bounded for NotNan<T> {
|
||||
fn min_value() -> Self {
|
||||
NotNan(Bounded::min_value())
|
||||
}
|
||||
|
||||
fn max_value() -> Self {
|
||||
NotNan(Bounded::max_value())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float + FromPrimitive> FromPrimitive for NotNan<T> {
|
||||
fn from_i64(n: i64) -> Option<Self> { T::from_i64(n).and_then(|n| NotNan::new(n).ok()) }
|
||||
fn from_u64(n: u64) -> Option<Self> { T::from_u64(n).and_then(|n| NotNan::new(n).ok()) }
|
||||
|
||||
fn from_isize(n: isize) -> Option<Self> { T::from_isize(n).and_then(|n| NotNan::new(n).ok()) }
|
||||
fn from_i8(n: i8) -> Option<Self> { T::from_i8(n).and_then(|n| NotNan::new(n).ok()) }
|
||||
fn from_i16(n: i16) -> Option<Self> { T::from_i16(n).and_then(|n| NotNan::new(n).ok()) }
|
||||
fn from_i32(n: i32) -> Option<Self> { T::from_i32(n).and_then(|n| NotNan::new(n).ok()) }
|
||||
fn from_usize(n: usize) -> Option<Self> { T::from_usize(n).and_then(|n| NotNan::new(n).ok()) }
|
||||
fn from_u8(n: u8) -> Option<Self> { T::from_u8(n).and_then(|n| NotNan::new(n).ok()) }
|
||||
fn from_u16(n: u16) -> Option<Self> { T::from_u16(n).and_then(|n| NotNan::new(n).ok()) }
|
||||
fn from_u32(n: u32) -> Option<Self> { T::from_u32(n).and_then(|n| NotNan::new(n).ok()) }
|
||||
fn from_f32(n: f32) -> Option<Self> { T::from_f32(n).and_then(|n| NotNan::new(n).ok()) }
|
||||
fn from_f64(n: f64) -> Option<Self> { T::from_f64(n).and_then(|n| NotNan::new(n).ok()) }
|
||||
}
|
||||
|
||||
impl<T: Float + ToPrimitive> ToPrimitive for NotNan<T> {
|
||||
fn to_i64(&self) -> Option<i64> { self.0.to_i64() }
|
||||
fn to_u64(&self) -> Option<u64> { self.0.to_u64() }
|
||||
|
||||
fn to_isize(&self) -> Option<isize> { self.0.to_isize() }
|
||||
fn to_i8(&self) -> Option<i8> { self.0.to_i8() }
|
||||
fn to_i16(&self) -> Option<i16> { self.0.to_i16() }
|
||||
fn to_i32(&self) -> Option<i32> { self.0.to_i32() }
|
||||
fn to_usize(&self) -> Option<usize> { self.0.to_usize() }
|
||||
fn to_u8(&self) -> Option<u8> { self.0.to_u8() }
|
||||
fn to_u16(&self) -> Option<u16> { self.0.to_u16() }
|
||||
fn to_u32(&self) -> Option<u32> { self.0.to_u32() }
|
||||
fn to_f32(&self) -> Option<f32> { self.0.to_f32() }
|
||||
fn to_f64(&self) -> Option<f64> { self.0.to_f64() }
|
||||
}
|
||||
|
||||
/// An error indicating a parse error from a string for `NotNan`.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum ParseNotNanError<E> {
|
||||
/// A plain parse error from the underlying float type.
|
||||
ParseFloatError(E),
|
||||
/// The parsed float value resulted in a NaN.
|
||||
IsNaN,
|
||||
}
|
||||
|
||||
impl<E: fmt::Debug> Error for ParseNotNanError<E> {
|
||||
fn description(&self) -> &str {
|
||||
return "Error parsing a not-NaN floating point value";
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: fmt::Debug> fmt::Display for ParseNotNanError<E> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
<Self as fmt::Debug>::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float + Num> Num for NotNan<T> {
|
||||
type FromStrRadixErr = ParseNotNanError<T::FromStrRadixErr>;
|
||||
|
||||
fn from_str_radix(src: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {
|
||||
T::from_str_radix(src, radix)
|
||||
.map_err(|err| ParseNotNanError::ParseFloatError(err))
|
||||
.and_then(|n| NotNan::new(n).map_err(|_| ParseNotNanError::IsNaN))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float + Signed> Signed for NotNan<T> {
|
||||
fn abs(&self) -> Self { NotNan(self.0.abs()) }
|
||||
|
||||
fn abs_sub(&self, other: &Self) -> Self {
|
||||
NotNan::new(self.0.abs_sub(other.0)).expect("Subtraction resulted in NaN")
|
||||
}
|
||||
|
||||
fn signum(&self) -> Self { NotNan(self.0.signum()) }
|
||||
fn is_positive(&self) -> bool { self.0.is_positive() }
|
||||
fn is_negative(&self) -> bool { self.0.is_negative() }
|
||||
}
|
||||
|
||||
impl<T: Float + NumCast> NumCast for NotNan<T> {
|
||||
fn from<F: ToPrimitive>(n: F) -> Option<Self> {
|
||||
T::from(n).and_then(|n| NotNan::new(n).ok())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
mod impl_serde {
|
||||
extern crate serde;
|
||||
use self::serde::{Serialize, Serializer, Deserialize, Deserializer};
|
||||
use self::serde::de::{Error, Unexpected};
|
||||
use super::{OrderedFloat, NotNan};
|
||||
use num_traits::Float;
|
||||
use std::f64;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate serde_test;
|
||||
#[cfg(test)]
|
||||
use self::serde_test::{Token, assert_tokens, assert_de_tokens_error};
|
||||
|
||||
impl<T: Float + Serialize> Serialize for OrderedFloat<T> {
|
||||
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
|
||||
self.0.serialize(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, T: Float + Deserialize<'de>> Deserialize<'de> for OrderedFloat<T> {
|
||||
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
|
||||
T::deserialize(d).map(OrderedFloat)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Float + Serialize> Serialize for NotNan<T> {
|
||||
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
|
||||
self.0.serialize(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, T: Float + Deserialize<'de>> Deserialize<'de> for NotNan<T> {
|
||||
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
|
||||
let float = T::deserialize(d)?;
|
||||
NotNan::new(float).map_err(|_| {
|
||||
Error::invalid_value(Unexpected::Float(f64::NAN), &"float (but not NaN)")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ordered_float() {
|
||||
let float = OrderedFloat(1.0f64);
|
||||
assert_tokens(&float, &[Token::F64(1.0)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_not_nan() {
|
||||
let float = NotNan(1.0f64);
|
||||
assert_tokens(&float, &[Token::F64(1.0)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fail_on_nan() {
|
||||
assert_de_tokens_error::<NotNan<f64>>(
|
||||
&[Token::F64(f64::NAN)],
|
||||
"invalid value: floating point `NaN`, expected float (but not NaN)");
|
||||
}
|
||||
}
|
|
@ -1,524 +0,0 @@
|
|||
extern crate num_traits;
|
||||
extern crate ordered_float;
|
||||
|
||||
pub use ordered_float::*;
|
||||
pub use num_traits::{Bounded, Float, FromPrimitive, Num, One, Signed, ToPrimitive, Zero};
|
||||
pub use std::cmp::Ordering::*;
|
||||
pub use std::{f32, f64, panic};
|
||||
|
||||
pub use std::collections::hash_map::RandomState;
|
||||
pub use std::collections::HashSet;
|
||||
pub use std::hash::*;
|
||||
|
||||
#[test]
|
||||
fn ordered_f32_compare_regular_floats() {
|
||||
assert_eq!(OrderedFloat(7.0f32).cmp(&OrderedFloat(7.0)), Equal);
|
||||
assert_eq!(OrderedFloat(8.0f32).cmp(&OrderedFloat(7.0)), Greater);
|
||||
assert_eq!(OrderedFloat(4.0f32).cmp(&OrderedFloat(7.0)), Less);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f32_compare_regular_floats_op() {
|
||||
assert!(OrderedFloat(7.0f32) == OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(7.0f32) <= OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(7.0f32) >= OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(8.0f32) > OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(8.0f32) >= OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(4.0f32) < OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(4.0f32) <= OrderedFloat(7.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f32_compare_nan() {
|
||||
let f32_nan: f32 = Float::nan();
|
||||
assert_eq!(OrderedFloat(f32_nan).cmp(&OrderedFloat(Float::nan())), Equal);
|
||||
assert_eq!(OrderedFloat(f32_nan).cmp(&OrderedFloat(-100000.0f32)), Greater);
|
||||
assert_eq!(OrderedFloat(-100.0f32).cmp(&OrderedFloat(Float::nan())), Less);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f32_compare_nan_op() {
|
||||
let f32_nan: OrderedFloat<f32> = OrderedFloat(Float::nan());
|
||||
assert!(f32_nan == f32_nan);
|
||||
assert!(f32_nan <= f32_nan);
|
||||
assert!(f32_nan >= f32_nan);
|
||||
assert!(f32_nan > OrderedFloat(-100000.0f32));
|
||||
assert!(f32_nan >= OrderedFloat(-100000.0f32));
|
||||
assert!(OrderedFloat(-100.0f32) < f32_nan);
|
||||
assert!(OrderedFloat(-100.0f32) <= f32_nan);
|
||||
assert!(f32_nan > OrderedFloat(Float::infinity()));
|
||||
assert!(f32_nan >= OrderedFloat(Float::infinity()));
|
||||
assert!(f32_nan > OrderedFloat(Float::neg_infinity()));
|
||||
assert!(f32_nan >= OrderedFloat(Float::neg_infinity()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f64_compare_regular_floats() {
|
||||
assert_eq!(OrderedFloat(7.0f64).cmp(&OrderedFloat(7.0)), Equal);
|
||||
assert_eq!(OrderedFloat(8.0f64).cmp(&OrderedFloat(7.0)), Greater);
|
||||
assert_eq!(OrderedFloat(4.0f64).cmp(&OrderedFloat(7.0)), Less);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_zero() {
|
||||
assert_eq!(NotNan::<f32>::zero(), NotNan::from(0.0f32));
|
||||
assert!(NotNan::<f32>::zero().is_zero());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_one() {
|
||||
assert_eq!(NotNan::<f32>::one(), NotNan::from(1.0f32))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_bounded() {
|
||||
assert_eq!(NotNan::<f32>::min_value(), NotNan::from(<f32 as Bounded>::min_value()));
|
||||
assert_eq!(NotNan::<f32>::max_value(), NotNan::from(<f32 as Bounded>::max_value()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_from_primitive() {
|
||||
assert_eq!(NotNan::<f32>::from_i8(42i8), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_u8(42u8), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_i16(42i16), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_u16(42u16), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_i32(42i32), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_u32(42u32), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_i64(42i64), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_u64(42u64), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_isize(42isize), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_usize(42usize), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_f32(42f32), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_f32(42f32), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_f64(42f64), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_f64(42f64), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f32>::from_f32(Float::nan()), None);
|
||||
assert_eq!(NotNan::<f32>::from_f64(Float::nan()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_to_primitive() {
|
||||
let x = NotNan::from(42.0f32);
|
||||
assert_eq!(x.to_u8(), Some(42u8));
|
||||
assert_eq!(x.to_i8(), Some(42i8));
|
||||
assert_eq!(x.to_u16(), Some(42u16));
|
||||
assert_eq!(x.to_i16(), Some(42i16));
|
||||
assert_eq!(x.to_u32(), Some(42u32));
|
||||
assert_eq!(x.to_i32(), Some(42i32));
|
||||
assert_eq!(x.to_u64(), Some(42u64));
|
||||
assert_eq!(x.to_i64(), Some(42i64));
|
||||
assert_eq!(x.to_usize(), Some(42usize));
|
||||
assert_eq!(x.to_isize(), Some(42isize));
|
||||
assert_eq!(x.to_f32(), Some(42f32));
|
||||
assert_eq!(x.to_f32(), Some(42f32));
|
||||
assert_eq!(x.to_f64(), Some(42f64));
|
||||
assert_eq!(x.to_f64(), Some(42f64));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_num() {
|
||||
assert_eq!(NotNan::<f32>::from_str_radix("42.0", 10).unwrap(), NotNan::from(42.0f32));
|
||||
assert!(NotNan::<f32>::from_str_radix("NaN", 10).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_signed() {
|
||||
assert_eq!(NotNan::from(42f32).abs(), NotNan::from(42f32));
|
||||
assert_eq!(NotNan::from(-42f32).abs(), NotNan::from(42f32));
|
||||
|
||||
assert_eq!(NotNan::from(50f32).abs_sub(&NotNan::from(8f32)), NotNan::from(42f32));
|
||||
assert_eq!(NotNan::from(8f32).abs_sub(&NotNan::from(50f32)), NotNan::from(0f32));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_num_cast() {
|
||||
assert_eq!(<NotNan<f32> as num_traits::NumCast>::from(42), Some(NotNan::from(42f32)));
|
||||
assert_eq!(<NotNan<f32> as num_traits::NumCast>::from(f32::nan()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f64_compare_nan() {
|
||||
let f64_nan: f64 = Float::nan();
|
||||
assert_eq!(
|
||||
OrderedFloat(f64_nan).cmp(&OrderedFloat(Float::nan())),
|
||||
Equal
|
||||
);
|
||||
assert_eq!(
|
||||
OrderedFloat(f64_nan).cmp(&OrderedFloat(-100000.0f64)),
|
||||
Greater
|
||||
);
|
||||
assert_eq!(
|
||||
OrderedFloat(-100.0f64).cmp(&OrderedFloat(Float::nan())),
|
||||
Less
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f64_compare_regular_floats_op() {
|
||||
assert!(OrderedFloat(7.0) == OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(7.0) <= OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(7.0) >= OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(8.0) > OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(8.0) >= OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(4.0) < OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(4.0) <= OrderedFloat(7.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f64_compare_nan_op() {
|
||||
let f64_nan: OrderedFloat<f64> = OrderedFloat(Float::nan());
|
||||
assert!(f64_nan == f64_nan);
|
||||
assert!(f64_nan <= f64_nan);
|
||||
assert!(f64_nan >= f64_nan);
|
||||
assert!(f64_nan > OrderedFloat(-100000.0));
|
||||
assert!(f64_nan >= OrderedFloat(-100000.0));
|
||||
assert!(OrderedFloat(-100.0) < f64_nan);
|
||||
assert!(OrderedFloat(-100.0) <= f64_nan);
|
||||
assert!(f64_nan > OrderedFloat(Float::infinity()));
|
||||
assert!(f64_nan >= OrderedFloat(Float::infinity()));
|
||||
assert!(f64_nan > OrderedFloat(Float::neg_infinity()));
|
||||
assert!(f64_nan >= OrderedFloat(Float::neg_infinity()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_compare_regular_floats() {
|
||||
assert_eq!(NotNan::from(7.0f32).cmp(&NotNan::from(7.0)), Equal);
|
||||
assert_eq!(NotNan::from(8.0f32).cmp(&NotNan::from(7.0)), Greater);
|
||||
assert_eq!(NotNan::from(4.0f32).cmp(&NotNan::from(7.0)), Less);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_fail_when_constructing_with_nan() {
|
||||
let f32_nan: f32 = Float::nan();
|
||||
assert!(NotNan::new(f32_nan).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_calculate_correctly() {
|
||||
assert_eq!(
|
||||
*(NotNan::from(5.0f32) + NotNan::from(4.0f32)),
|
||||
5.0f32 + 4.0f32
|
||||
);
|
||||
assert_eq!(*(NotNan::from(5.0f32) + 4.0f32), 5.0f32 + 4.0f32);
|
||||
assert_eq!(
|
||||
*(NotNan::from(5.0f32) - NotNan::from(4.0f32)),
|
||||
5.0f32 - 4.0f32
|
||||
);
|
||||
assert_eq!(*(NotNan::from(5.0f32) - 4.0f32), 5.0f32 - 4.0f32);
|
||||
assert_eq!(
|
||||
*(NotNan::from(5.0f32) * NotNan::from(4.0f32)),
|
||||
5.0f32 * 4.0f32
|
||||
);
|
||||
assert_eq!(*(NotNan::from(5.0f32) * 4.0f32), 5.0f32 * 4.0f32);
|
||||
assert_eq!(
|
||||
*(NotNan::from(8.0f32) / NotNan::from(4.0f32)),
|
||||
8.0f32 / 4.0f32
|
||||
);
|
||||
assert_eq!(*(NotNan::from(8.0f32) / 4.0f32), 8.0f32 / 4.0f32);
|
||||
assert_eq!(
|
||||
*(NotNan::from(8.0f32) % NotNan::from(4.0f32)),
|
||||
8.0f32 % 4.0f32
|
||||
);
|
||||
assert_eq!(*(NotNan::from(8.0f32) % 4.0f32), 8.0f32 % 4.0f32);
|
||||
assert_eq!(*(-NotNan::from(1.0f32)), -1.0f32);
|
||||
|
||||
assert!(panic::catch_unwind(|| NotNan::from(0.0f32) + f32::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNan::from(0.0f32) - f32::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNan::from(0.0f32) * f32::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNan::from(0.0f32) / f32::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNan::from(0.0f32) % f32::NAN).is_err());
|
||||
|
||||
let mut number = NotNan::from(5.0f32);
|
||||
number += NotNan::from(4.0f32);
|
||||
assert_eq!(*number, 9.0f32);
|
||||
number -= NotNan::from(4.0f32);
|
||||
assert_eq!(*number, 5.0f32);
|
||||
number *= NotNan::from(4.0f32);
|
||||
assert_eq!(*number, 20.0f32);
|
||||
number /= NotNan::from(4.0f32);
|
||||
assert_eq!(*number, 5.0f32);
|
||||
number %= NotNan::from(4.0f32);
|
||||
assert_eq!(*number, 1.0f32);
|
||||
|
||||
number = NotNan::from(5.0f32);
|
||||
number += 4.0f32;
|
||||
assert_eq!(*number, 9.0f32);
|
||||
number -= 4.0f32;
|
||||
assert_eq!(*number, 5.0f32);
|
||||
number *= 4.0f32;
|
||||
assert_eq!(*number, 20.0f32);
|
||||
number /= 4.0f32;
|
||||
assert_eq!(*number, 5.0f32);
|
||||
number %= 4.0f32;
|
||||
assert_eq!(*number, 1.0f32);
|
||||
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNan::from(0.0f32);
|
||||
tmp += f32::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNan::from(0.0f32);
|
||||
tmp -= f32::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNan::from(0.0f32);
|
||||
tmp *= f32::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNan::from(0.0f32);
|
||||
tmp /= f32::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNan::from(0.0f32);
|
||||
tmp %= f32::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_compare_regular_floats() {
|
||||
assert_eq!(NotNan::from(7.0f64).cmp(&NotNan::from(7.0)), Equal);
|
||||
assert_eq!(NotNan::from(8.0f64).cmp(&NotNan::from(7.0)), Greater);
|
||||
assert_eq!(NotNan::from(4.0f64).cmp(&NotNan::from(7.0)), Less);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_fail_when_constructing_with_nan() {
|
||||
let f64_nan: f64 = Float::nan();
|
||||
assert!(NotNan::new(f64_nan).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_calculate_correctly() {
|
||||
assert_eq!(
|
||||
*(NotNan::from(5.0f64) + NotNan::from(4.0f64)),
|
||||
5.0f64 + 4.0f64
|
||||
);
|
||||
assert_eq!(*(NotNan::from(5.0f64) + 4.0f64), 5.0f64 + 4.0f64);
|
||||
assert_eq!(
|
||||
*(NotNan::from(5.0f64) - NotNan::from(4.0f64)),
|
||||
5.0f64 - 4.0f64
|
||||
);
|
||||
assert_eq!(*(NotNan::from(5.0f64) - 4.0f64), 5.0f64 - 4.0f64);
|
||||
assert_eq!(
|
||||
*(NotNan::from(5.0f64) * NotNan::from(4.0f64)),
|
||||
5.0f64 * 4.0f64
|
||||
);
|
||||
assert_eq!(*(NotNan::from(5.0f64) * 4.0f64), 5.0f64 * 4.0f64);
|
||||
assert_eq!(
|
||||
*(NotNan::from(8.0f64) / NotNan::from(4.0f64)),
|
||||
8.0f64 / 4.0f64
|
||||
);
|
||||
assert_eq!(*(NotNan::from(8.0f64) / 4.0f64), 8.0f64 / 4.0f64);
|
||||
assert_eq!(
|
||||
*(NotNan::from(8.0f64) % NotNan::from(4.0f64)),
|
||||
8.0f64 % 4.0f64
|
||||
);
|
||||
assert_eq!(*(NotNan::from(8.0f64) % 4.0f64), 8.0f64 % 4.0f64);
|
||||
assert_eq!(*(-NotNan::from(1.0f64)), -1.0f64);
|
||||
|
||||
assert!(panic::catch_unwind(|| NotNan::from(0.0f64) + f64::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNan::from(0.0f64) - f64::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNan::from(0.0f64) * f64::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNan::from(0.0f64) / f64::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNan::from(0.0f64) % f64::NAN).is_err());
|
||||
|
||||
let mut number = NotNan::from(5.0f64);
|
||||
number += NotNan::from(4.0f64);
|
||||
assert_eq!(*number, 9.0f64);
|
||||
number -= NotNan::from(4.0f64);
|
||||
assert_eq!(*number, 5.0f64);
|
||||
number *= NotNan::from(4.0f64);
|
||||
assert_eq!(*number, 20.0f64);
|
||||
number /= NotNan::from(4.0f64);
|
||||
assert_eq!(*number, 5.0f64);
|
||||
number %= NotNan::from(4.0f64);
|
||||
assert_eq!(*number, 1.0f64);
|
||||
|
||||
number = NotNan::from(5.0f64);
|
||||
number += 4.0f64;
|
||||
assert_eq!(*number, 9.0f64);
|
||||
number -= 4.0f64;
|
||||
assert_eq!(*number, 5.0f64);
|
||||
number *= 4.0f64;
|
||||
assert_eq!(*number, 20.0f64);
|
||||
number /= 4.0f64;
|
||||
assert_eq!(*number, 5.0f64);
|
||||
number %= 4.0f64;
|
||||
assert_eq!(*number, 1.0f64);
|
||||
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNan::from(0.0f64);
|
||||
tmp += f64::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNan::from(0.0f64);
|
||||
tmp -= f64::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNan::from(0.0f64);
|
||||
tmp *= f64::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNan::from(0.0f64);
|
||||
tmp /= f64::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNan::from(0.0f64);
|
||||
tmp %= f64::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_zero() {
|
||||
assert_eq!(NotNan::<f64>::zero(), NotNan::from(0.0f64));
|
||||
assert!(NotNan::<f64>::zero().is_zero());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_one() {
|
||||
assert_eq!(NotNan::<f64>::one(), NotNan::from(1.0f64))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_bounded() {
|
||||
assert_eq!(NotNan::<f64>::min_value(), NotNan::from(<f64 as Bounded>::min_value()));
|
||||
assert_eq!(NotNan::<f64>::max_value(), NotNan::from(<f64 as Bounded>::max_value()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_from_primitive() {
|
||||
assert_eq!(NotNan::<f64>::from_i8(42i8), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_u8(42u8), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_i16(42i16), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_u16(42u16), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_i32(42i32), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_u32(42u32), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_i64(42i64), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_u64(42u64), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_isize(42isize), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_usize(42usize), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_f64(42f64), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_f64(42f64), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_f64(42f64), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_f64(42f64), Some(NotNan::from(42.0)));
|
||||
assert_eq!(NotNan::<f64>::from_f64(Float::nan()), None);
|
||||
assert_eq!(NotNan::<f64>::from_f64(Float::nan()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_to_primitive() {
|
||||
let x = NotNan::from(42.0f64);
|
||||
assert_eq!(x.to_u8(), Some(42u8));
|
||||
assert_eq!(x.to_i8(), Some(42i8));
|
||||
assert_eq!(x.to_u16(), Some(42u16));
|
||||
assert_eq!(x.to_i16(), Some(42i16));
|
||||
assert_eq!(x.to_u32(), Some(42u32));
|
||||
assert_eq!(x.to_i32(), Some(42i32));
|
||||
assert_eq!(x.to_u64(), Some(42u64));
|
||||
assert_eq!(x.to_i64(), Some(42i64));
|
||||
assert_eq!(x.to_usize(), Some(42usize));
|
||||
assert_eq!(x.to_isize(), Some(42isize));
|
||||
assert_eq!(x.to_f64(), Some(42f64));
|
||||
assert_eq!(x.to_f64(), Some(42f64));
|
||||
assert_eq!(x.to_f64(), Some(42f64));
|
||||
assert_eq!(x.to_f64(), Some(42f64));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_num() {
|
||||
assert_eq!(NotNan::<f64>::from_str_radix("42.0", 10).unwrap(), NotNan::from(42.0f64));
|
||||
assert!(NotNan::<f64>::from_str_radix("NaN", 10).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_signed() {
|
||||
assert_eq!(NotNan::from(42f64).abs(), NotNan::from(42f64));
|
||||
assert_eq!(NotNan::from(-42f64).abs(), NotNan::from(42f64));
|
||||
|
||||
assert_eq!(NotNan::from(50f64).abs_sub(&NotNan::from(8f64)), NotNan::from(42f64));
|
||||
assert_eq!(NotNan::from(8f64).abs_sub(&NotNan::from(50f64)), NotNan::from(0f64));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_num_cast() {
|
||||
assert_eq!(<NotNan<f64> as num_traits::NumCast>::from(42), Some(NotNan::from(42f64)));
|
||||
assert_eq!(<NotNan<f64> as num_traits::NumCast>::from(f64::nan()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_zero_and_neg_zero_to_the_same_hc() {
|
||||
let state = RandomState::new();
|
||||
let mut h1 = state.build_hasher();
|
||||
let mut h2 = state.build_hasher();
|
||||
OrderedFloat::from(0f64).hash(&mut h1);
|
||||
OrderedFloat::from(-0f64).hash(&mut h2);
|
||||
assert_eq!(h1.finish(), h2.finish());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_inf_and_neg_inf_to_different_hcs() {
|
||||
let state = RandomState::new();
|
||||
let mut h1 = state.build_hasher();
|
||||
let mut h2 = state.build_hasher();
|
||||
OrderedFloat::from(f64::INFINITY).hash(&mut h1);
|
||||
OrderedFloat::from(f64::NEG_INFINITY).hash(&mut h2);
|
||||
assert!(h1.finish() != h2.finish());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_is_good_for_whole_numbers() {
|
||||
let state = RandomState::new();
|
||||
let limit = 10000;
|
||||
|
||||
let mut set = ::std::collections::HashSet::with_capacity(limit);
|
||||
for i in 0..limit {
|
||||
let mut h = state.build_hasher();
|
||||
OrderedFloat::from(i as f64).hash(&mut h);
|
||||
set.insert(h.finish());
|
||||
}
|
||||
|
||||
// This allows 100 collisions, which is far too
|
||||
// many, but should guard against transient issues
|
||||
// that will result from using RandomState
|
||||
let pct_unique = set.len() as f64 / limit as f64;
|
||||
assert!(0.99f64 < pct_unique, "percent-unique={}", pct_unique);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_is_good_for_fractional_numbers() {
|
||||
let state = RandomState::new();
|
||||
let limit = 10000;
|
||||
|
||||
let mut set = ::std::collections::HashSet::with_capacity(limit);
|
||||
for i in 0..limit {
|
||||
let mut h = state.build_hasher();
|
||||
OrderedFloat::from(i as f64 * (1f64 / limit as f64)).hash(&mut h);
|
||||
set.insert(h.finish());
|
||||
}
|
||||
|
||||
// This allows 100 collisions, which is far too
|
||||
// many, but should guard against transient issues
|
||||
// that will result from using RandomState
|
||||
let pct_unique = set.len() as f64 / limit as f64;
|
||||
assert!(0.99f64 < pct_unique, "percent-unique={}", pct_unique);
|
||||
}
|
|
@ -1,526 +0,0 @@
|
|||
#![allow(deprecated)]
|
||||
|
||||
extern crate num_traits;
|
||||
extern crate ordered_float;
|
||||
|
||||
pub use ordered_float::*;
|
||||
pub use num_traits::{Bounded, Float, FromPrimitive, Num, One, Signed, ToPrimitive, Zero};
|
||||
pub use std::cmp::Ordering::*;
|
||||
pub use std::{f32, f64, panic};
|
||||
|
||||
pub use std::collections::hash_map::RandomState;
|
||||
pub use std::collections::HashSet;
|
||||
pub use std::hash::*;
|
||||
|
||||
#[test]
|
||||
fn ordered_f32_compare_regular_floats() {
|
||||
assert_eq!(OrderedFloat(7.0f32).cmp(&OrderedFloat(7.0)), Equal);
|
||||
assert_eq!(OrderedFloat(8.0f32).cmp(&OrderedFloat(7.0)), Greater);
|
||||
assert_eq!(OrderedFloat(4.0f32).cmp(&OrderedFloat(7.0)), Less);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f32_compare_regular_floats_op() {
|
||||
assert!(OrderedFloat(7.0f32) == OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(7.0f32) <= OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(7.0f32) >= OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(8.0f32) > OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(8.0f32) >= OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(4.0f32) < OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(4.0f32) <= OrderedFloat(7.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f32_compare_nan() {
|
||||
let f32_nan: f32 = Float::nan();
|
||||
assert_eq!(OrderedFloat(f32_nan).cmp(&OrderedFloat(Float::nan())), Equal);
|
||||
assert_eq!(OrderedFloat(f32_nan).cmp(&OrderedFloat(-100000.0f32)), Greater);
|
||||
assert_eq!(OrderedFloat(-100.0f32).cmp(&OrderedFloat(Float::nan())), Less);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f32_compare_nan_op() {
|
||||
let f32_nan: OrderedFloat<f32> = OrderedFloat(Float::nan());
|
||||
assert!(f32_nan == f32_nan);
|
||||
assert!(f32_nan <= f32_nan);
|
||||
assert!(f32_nan >= f32_nan);
|
||||
assert!(f32_nan > OrderedFloat(-100000.0f32));
|
||||
assert!(f32_nan >= OrderedFloat(-100000.0f32));
|
||||
assert!(OrderedFloat(-100.0f32) < f32_nan);
|
||||
assert!(OrderedFloat(-100.0f32) <= f32_nan);
|
||||
assert!(f32_nan > OrderedFloat(Float::infinity()));
|
||||
assert!(f32_nan >= OrderedFloat(Float::infinity()));
|
||||
assert!(f32_nan > OrderedFloat(Float::neg_infinity()));
|
||||
assert!(f32_nan >= OrderedFloat(Float::neg_infinity()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f64_compare_regular_floats() {
|
||||
assert_eq!(OrderedFloat(7.0f64).cmp(&OrderedFloat(7.0)), Equal);
|
||||
assert_eq!(OrderedFloat(8.0f64).cmp(&OrderedFloat(7.0)), Greater);
|
||||
assert_eq!(OrderedFloat(4.0f64).cmp(&OrderedFloat(7.0)), Less);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_zero() {
|
||||
assert_eq!(NotNaN::<f32>::zero(), NotNaN::from(0.0f32));
|
||||
assert!(NotNaN::<f32>::zero().is_zero());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_one() {
|
||||
assert_eq!(NotNaN::<f32>::one(), NotNaN::from(1.0f32))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_bounded() {
|
||||
assert_eq!(NotNaN::<f32>::min_value(), NotNaN::from(<f32 as Bounded>::min_value()));
|
||||
assert_eq!(NotNaN::<f32>::max_value(), NotNaN::from(<f32 as Bounded>::max_value()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_from_primitive() {
|
||||
assert_eq!(NotNaN::<f32>::from_i8(42i8), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_u8(42u8), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_i16(42i16), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_u16(42u16), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_i32(42i32), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_u32(42u32), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_i64(42i64), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_u64(42u64), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_isize(42isize), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_usize(42usize), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_f32(42f32), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_f32(42f32), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_f64(42f64), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_f64(42f64), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f32>::from_f32(Float::nan()), None);
|
||||
assert_eq!(NotNaN::<f32>::from_f64(Float::nan()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_to_primitive() {
|
||||
let x = NotNaN::from(42.0f32);
|
||||
assert_eq!(x.to_u8(), Some(42u8));
|
||||
assert_eq!(x.to_i8(), Some(42i8));
|
||||
assert_eq!(x.to_u16(), Some(42u16));
|
||||
assert_eq!(x.to_i16(), Some(42i16));
|
||||
assert_eq!(x.to_u32(), Some(42u32));
|
||||
assert_eq!(x.to_i32(), Some(42i32));
|
||||
assert_eq!(x.to_u64(), Some(42u64));
|
||||
assert_eq!(x.to_i64(), Some(42i64));
|
||||
assert_eq!(x.to_usize(), Some(42usize));
|
||||
assert_eq!(x.to_isize(), Some(42isize));
|
||||
assert_eq!(x.to_f32(), Some(42f32));
|
||||
assert_eq!(x.to_f32(), Some(42f32));
|
||||
assert_eq!(x.to_f64(), Some(42f64));
|
||||
assert_eq!(x.to_f64(), Some(42f64));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_num() {
|
||||
assert_eq!(NotNaN::<f32>::from_str_radix("42.0", 10).unwrap(), NotNaN::from(42.0f32));
|
||||
assert!(NotNaN::<f32>::from_str_radix("NaN", 10).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_signed() {
|
||||
assert_eq!(NotNaN::from(42f32).abs(), NotNaN::from(42f32));
|
||||
assert_eq!(NotNaN::from(-42f32).abs(), NotNaN::from(42f32));
|
||||
|
||||
assert_eq!(NotNaN::from(50f32).abs_sub(&NotNaN::from(8f32)), NotNaN::from(42f32));
|
||||
assert_eq!(NotNaN::from(8f32).abs_sub(&NotNaN::from(50f32)), NotNaN::from(0f32));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_num_cast() {
|
||||
assert_eq!(<NotNaN<f32> as num_traits::NumCast>::from(42), Some(NotNaN::from(42f32)));
|
||||
assert_eq!(<NotNaN<f32> as num_traits::NumCast>::from(f32::nan()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f64_compare_nan() {
|
||||
let f64_nan: f64 = Float::nan();
|
||||
assert_eq!(
|
||||
OrderedFloat(f64_nan).cmp(&OrderedFloat(Float::nan())),
|
||||
Equal
|
||||
);
|
||||
assert_eq!(
|
||||
OrderedFloat(f64_nan).cmp(&OrderedFloat(-100000.0f64)),
|
||||
Greater
|
||||
);
|
||||
assert_eq!(
|
||||
OrderedFloat(-100.0f64).cmp(&OrderedFloat(Float::nan())),
|
||||
Less
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f64_compare_regular_floats_op() {
|
||||
assert!(OrderedFloat(7.0) == OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(7.0) <= OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(7.0) >= OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(8.0) > OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(8.0) >= OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(4.0) < OrderedFloat(7.0));
|
||||
assert!(OrderedFloat(4.0) <= OrderedFloat(7.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_f64_compare_nan_op() {
|
||||
let f64_nan: OrderedFloat<f64> = OrderedFloat(Float::nan());
|
||||
assert!(f64_nan == f64_nan);
|
||||
assert!(f64_nan <= f64_nan);
|
||||
assert!(f64_nan >= f64_nan);
|
||||
assert!(f64_nan > OrderedFloat(-100000.0));
|
||||
assert!(f64_nan >= OrderedFloat(-100000.0));
|
||||
assert!(OrderedFloat(-100.0) < f64_nan);
|
||||
assert!(OrderedFloat(-100.0) <= f64_nan);
|
||||
assert!(f64_nan > OrderedFloat(Float::infinity()));
|
||||
assert!(f64_nan >= OrderedFloat(Float::infinity()));
|
||||
assert!(f64_nan > OrderedFloat(Float::neg_infinity()));
|
||||
assert!(f64_nan >= OrderedFloat(Float::neg_infinity()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_compare_regular_floats() {
|
||||
assert_eq!(NotNaN::from(7.0f32).cmp(&NotNaN::from(7.0)), Equal);
|
||||
assert_eq!(NotNaN::from(8.0f32).cmp(&NotNaN::from(7.0)), Greater);
|
||||
assert_eq!(NotNaN::from(4.0f32).cmp(&NotNaN::from(7.0)), Less);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_fail_when_constructing_with_nan() {
|
||||
let f32_nan: f32 = Float::nan();
|
||||
assert!(NotNaN::new(f32_nan).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan32_calculate_correctly() {
|
||||
assert_eq!(
|
||||
*(NotNaN::from(5.0f32) + NotNaN::from(4.0f32)),
|
||||
5.0f32 + 4.0f32
|
||||
);
|
||||
assert_eq!(*(NotNaN::from(5.0f32) + 4.0f32), 5.0f32 + 4.0f32);
|
||||
assert_eq!(
|
||||
*(NotNaN::from(5.0f32) - NotNaN::from(4.0f32)),
|
||||
5.0f32 - 4.0f32
|
||||
);
|
||||
assert_eq!(*(NotNaN::from(5.0f32) - 4.0f32), 5.0f32 - 4.0f32);
|
||||
assert_eq!(
|
||||
*(NotNaN::from(5.0f32) * NotNaN::from(4.0f32)),
|
||||
5.0f32 * 4.0f32
|
||||
);
|
||||
assert_eq!(*(NotNaN::from(5.0f32) * 4.0f32), 5.0f32 * 4.0f32);
|
||||
assert_eq!(
|
||||
*(NotNaN::from(8.0f32) / NotNaN::from(4.0f32)),
|
||||
8.0f32 / 4.0f32
|
||||
);
|
||||
assert_eq!(*(NotNaN::from(8.0f32) / 4.0f32), 8.0f32 / 4.0f32);
|
||||
assert_eq!(
|
||||
*(NotNaN::from(8.0f32) % NotNaN::from(4.0f32)),
|
||||
8.0f32 % 4.0f32
|
||||
);
|
||||
assert_eq!(*(NotNaN::from(8.0f32) % 4.0f32), 8.0f32 % 4.0f32);
|
||||
assert_eq!(*(-NotNaN::from(1.0f32)), -1.0f32);
|
||||
|
||||
assert!(panic::catch_unwind(|| NotNaN::from(0.0f32) + f32::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNaN::from(0.0f32) - f32::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNaN::from(0.0f32) * f32::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNaN::from(0.0f32) / f32::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNaN::from(0.0f32) % f32::NAN).is_err());
|
||||
|
||||
let mut number = NotNaN::from(5.0f32);
|
||||
number += NotNaN::from(4.0f32);
|
||||
assert_eq!(*number, 9.0f32);
|
||||
number -= NotNaN::from(4.0f32);
|
||||
assert_eq!(*number, 5.0f32);
|
||||
number *= NotNaN::from(4.0f32);
|
||||
assert_eq!(*number, 20.0f32);
|
||||
number /= NotNaN::from(4.0f32);
|
||||
assert_eq!(*number, 5.0f32);
|
||||
number %= NotNaN::from(4.0f32);
|
||||
assert_eq!(*number, 1.0f32);
|
||||
|
||||
number = NotNaN::from(5.0f32);
|
||||
number += 4.0f32;
|
||||
assert_eq!(*number, 9.0f32);
|
||||
number -= 4.0f32;
|
||||
assert_eq!(*number, 5.0f32);
|
||||
number *= 4.0f32;
|
||||
assert_eq!(*number, 20.0f32);
|
||||
number /= 4.0f32;
|
||||
assert_eq!(*number, 5.0f32);
|
||||
number %= 4.0f32;
|
||||
assert_eq!(*number, 1.0f32);
|
||||
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNaN::from(0.0f32);
|
||||
tmp += f32::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNaN::from(0.0f32);
|
||||
tmp -= f32::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNaN::from(0.0f32);
|
||||
tmp *= f32::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNaN::from(0.0f32);
|
||||
tmp /= f32::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNaN::from(0.0f32);
|
||||
tmp %= f32::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_compare_regular_floats() {
|
||||
assert_eq!(NotNaN::from(7.0f64).cmp(&NotNaN::from(7.0)), Equal);
|
||||
assert_eq!(NotNaN::from(8.0f64).cmp(&NotNaN::from(7.0)), Greater);
|
||||
assert_eq!(NotNaN::from(4.0f64).cmp(&NotNaN::from(7.0)), Less);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_fail_when_constructing_with_nan() {
|
||||
let f64_nan: f64 = Float::nan();
|
||||
assert!(NotNaN::new(f64_nan).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_calculate_correctly() {
|
||||
assert_eq!(
|
||||
*(NotNaN::from(5.0f64) + NotNaN::from(4.0f64)),
|
||||
5.0f64 + 4.0f64
|
||||
);
|
||||
assert_eq!(*(NotNaN::from(5.0f64) + 4.0f64), 5.0f64 + 4.0f64);
|
||||
assert_eq!(
|
||||
*(NotNaN::from(5.0f64) - NotNaN::from(4.0f64)),
|
||||
5.0f64 - 4.0f64
|
||||
);
|
||||
assert_eq!(*(NotNaN::from(5.0f64) - 4.0f64), 5.0f64 - 4.0f64);
|
||||
assert_eq!(
|
||||
*(NotNaN::from(5.0f64) * NotNaN::from(4.0f64)),
|
||||
5.0f64 * 4.0f64
|
||||
);
|
||||
assert_eq!(*(NotNaN::from(5.0f64) * 4.0f64), 5.0f64 * 4.0f64);
|
||||
assert_eq!(
|
||||
*(NotNaN::from(8.0f64) / NotNaN::from(4.0f64)),
|
||||
8.0f64 / 4.0f64
|
||||
);
|
||||
assert_eq!(*(NotNaN::from(8.0f64) / 4.0f64), 8.0f64 / 4.0f64);
|
||||
assert_eq!(
|
||||
*(NotNaN::from(8.0f64) % NotNaN::from(4.0f64)),
|
||||
8.0f64 % 4.0f64
|
||||
);
|
||||
assert_eq!(*(NotNaN::from(8.0f64) % 4.0f64), 8.0f64 % 4.0f64);
|
||||
assert_eq!(*(-NotNaN::from(1.0f64)), -1.0f64);
|
||||
|
||||
assert!(panic::catch_unwind(|| NotNaN::from(0.0f64) + f64::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNaN::from(0.0f64) - f64::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNaN::from(0.0f64) * f64::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNaN::from(0.0f64) / f64::NAN).is_err());
|
||||
assert!(panic::catch_unwind(|| NotNaN::from(0.0f64) % f64::NAN).is_err());
|
||||
|
||||
let mut number = NotNaN::from(5.0f64);
|
||||
number += NotNaN::from(4.0f64);
|
||||
assert_eq!(*number, 9.0f64);
|
||||
number -= NotNaN::from(4.0f64);
|
||||
assert_eq!(*number, 5.0f64);
|
||||
number *= NotNaN::from(4.0f64);
|
||||
assert_eq!(*number, 20.0f64);
|
||||
number /= NotNaN::from(4.0f64);
|
||||
assert_eq!(*number, 5.0f64);
|
||||
number %= NotNaN::from(4.0f64);
|
||||
assert_eq!(*number, 1.0f64);
|
||||
|
||||
number = NotNaN::from(5.0f64);
|
||||
number += 4.0f64;
|
||||
assert_eq!(*number, 9.0f64);
|
||||
number -= 4.0f64;
|
||||
assert_eq!(*number, 5.0f64);
|
||||
number *= 4.0f64;
|
||||
assert_eq!(*number, 20.0f64);
|
||||
number /= 4.0f64;
|
||||
assert_eq!(*number, 5.0f64);
|
||||
number %= 4.0f64;
|
||||
assert_eq!(*number, 1.0f64);
|
||||
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNaN::from(0.0f64);
|
||||
tmp += f64::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNaN::from(0.0f64);
|
||||
tmp -= f64::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNaN::from(0.0f64);
|
||||
tmp *= f64::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNaN::from(0.0f64);
|
||||
tmp /= f64::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
assert!(
|
||||
panic::catch_unwind(|| {
|
||||
let mut tmp = NotNaN::from(0.0f64);
|
||||
tmp %= f64::NAN;
|
||||
}).is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_zero() {
|
||||
assert_eq!(NotNaN::<f64>::zero(), NotNaN::from(0.0f64));
|
||||
assert!(NotNaN::<f64>::zero().is_zero());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_one() {
|
||||
assert_eq!(NotNaN::<f64>::one(), NotNaN::from(1.0f64))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_bounded() {
|
||||
assert_eq!(NotNaN::<f64>::min_value(), NotNaN::from(<f64 as Bounded>::min_value()));
|
||||
assert_eq!(NotNaN::<f64>::max_value(), NotNaN::from(<f64 as Bounded>::max_value()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_from_primitive() {
|
||||
assert_eq!(NotNaN::<f64>::from_i8(42i8), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_u8(42u8), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_i16(42i16), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_u16(42u16), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_i32(42i32), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_u32(42u32), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_i64(42i64), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_u64(42u64), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_isize(42isize), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_usize(42usize), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_f64(42f64), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_f64(42f64), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_f64(42f64), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_f64(42f64), Some(NotNaN::from(42.0)));
|
||||
assert_eq!(NotNaN::<f64>::from_f64(Float::nan()), None);
|
||||
assert_eq!(NotNaN::<f64>::from_f64(Float::nan()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_to_primitive() {
|
||||
let x = NotNaN::from(42.0f64);
|
||||
assert_eq!(x.to_u8(), Some(42u8));
|
||||
assert_eq!(x.to_i8(), Some(42i8));
|
||||
assert_eq!(x.to_u16(), Some(42u16));
|
||||
assert_eq!(x.to_i16(), Some(42i16));
|
||||
assert_eq!(x.to_u32(), Some(42u32));
|
||||
assert_eq!(x.to_i32(), Some(42i32));
|
||||
assert_eq!(x.to_u64(), Some(42u64));
|
||||
assert_eq!(x.to_i64(), Some(42i64));
|
||||
assert_eq!(x.to_usize(), Some(42usize));
|
||||
assert_eq!(x.to_isize(), Some(42isize));
|
||||
assert_eq!(x.to_f64(), Some(42f64));
|
||||
assert_eq!(x.to_f64(), Some(42f64));
|
||||
assert_eq!(x.to_f64(), Some(42f64));
|
||||
assert_eq!(x.to_f64(), Some(42f64));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_num() {
|
||||
assert_eq!(NotNaN::<f64>::from_str_radix("42.0", 10).unwrap(), NotNaN::from(42.0f64));
|
||||
assert!(NotNaN::<f64>::from_str_radix("NaN", 10).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_signed() {
|
||||
assert_eq!(NotNaN::from(42f64).abs(), NotNaN::from(42f64));
|
||||
assert_eq!(NotNaN::from(-42f64).abs(), NotNaN::from(42f64));
|
||||
|
||||
assert_eq!(NotNaN::from(50f64).abs_sub(&NotNaN::from(8f64)), NotNaN::from(42f64));
|
||||
assert_eq!(NotNaN::from(8f64).abs_sub(&NotNaN::from(50f64)), NotNaN::from(0f64));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_nan64_num_cast() {
|
||||
assert_eq!(<NotNaN<f64> as num_traits::NumCast>::from(42), Some(NotNaN::from(42f64)));
|
||||
assert_eq!(<NotNaN<f64> as num_traits::NumCast>::from(f64::nan()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_zero_and_neg_zero_to_the_same_hc() {
|
||||
let state = RandomState::new();
|
||||
let mut h1 = state.build_hasher();
|
||||
let mut h2 = state.build_hasher();
|
||||
OrderedFloat::from(0f64).hash(&mut h1);
|
||||
OrderedFloat::from(-0f64).hash(&mut h2);
|
||||
assert_eq!(h1.finish(), h2.finish());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_inf_and_neg_inf_to_different_hcs() {
|
||||
let state = RandomState::new();
|
||||
let mut h1 = state.build_hasher();
|
||||
let mut h2 = state.build_hasher();
|
||||
OrderedFloat::from(f64::INFINITY).hash(&mut h1);
|
||||
OrderedFloat::from(f64::NEG_INFINITY).hash(&mut h2);
|
||||
assert!(h1.finish() != h2.finish());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_is_good_for_whole_numbers() {
|
||||
let state = RandomState::new();
|
||||
let limit = 10000;
|
||||
|
||||
let mut set = ::std::collections::HashSet::with_capacity(limit);
|
||||
for i in 0..limit {
|
||||
let mut h = state.build_hasher();
|
||||
OrderedFloat::from(i as f64).hash(&mut h);
|
||||
set.insert(h.finish());
|
||||
}
|
||||
|
||||
// This allows 100 collisions, which is far too
|
||||
// many, but should guard against transient issues
|
||||
// that will result from using RandomState
|
||||
let pct_unique = set.len() as f64 / limit as f64;
|
||||
assert!(0.99f64 < pct_unique, "percent-unique={}", pct_unique);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_is_good_for_fractional_numbers() {
|
||||
let state = RandomState::new();
|
||||
let limit = 10000;
|
||||
|
||||
let mut set = ::std::collections::HashSet::with_capacity(limit);
|
||||
for i in 0..limit {
|
||||
let mut h = state.build_hasher();
|
||||
OrderedFloat::from(i as f64 * (1f64 / limit as f64)).hash(&mut h);
|
||||
set.insert(h.finish());
|
||||
}
|
||||
|
||||
// This allows 100 collisions, which is far too
|
||||
// many, but should guard against transient issues
|
||||
// that will result from using RandomState
|
||||
let pct_unique = set.len() as f64 / limit as f64;
|
||||
assert!(0.99f64 < pct_unique, "percent-unique={}", pct_unique);
|
||||
}
|
|
@ -1 +1 @@
|
|||
{"files":{".appveyor.yml":"64ac2899deda9060b9665cc8f58c3b3509c0c426d618e221ff4f2cb47a3201d5",".rustfmt.toml":"b484c99708d8cdb01be0ef680a15b8897112942d041fc656fc5622816b6b3412",".travis.yml":"dfdacfeafbc68d1bb8670ffe6484ab6d5077c559dfeee41b4aec68acf1ff81bc","Cargo.toml":"9b3c5075d37195c2344a7ce0ba7da407b6b15de68ed7cd2a9e844693e90c1412","LICENSE":"cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30","README.md":"9dc24375b49fef42f35dec42e316e21827d7337622f9e7cf36243cd28808797a","examples/README.md":"143767fc145bf167ce269a65138cb3f7086cb715b8bc4f73626da82966e646f4","examples/iterator.rs":"112d21743156cc86292b7ee2e1fe230e2531a4b14b62dd57c6fbc8e56bea775f","examples/simple-store.rs":"d36887921364bc36fe925ea8209b71a88a9ccca4775d502134b6c68e81372e88","run-all-examples.sh":"7f9d11d01017f77e1c9d26e3e82dfca8c6930deaec85e864458e33a7fa267de0","src/env.rs":"bbbf8f09f2529f7953d3db96283a6b59bbe66e2f320b9aa768e97b7f1d20b4c5","src/error.rs":"495112ac06104c4f83e033604a6121cb2e12140cf6450d38d8a7c8d9f5fea874","src/integer.rs":"ba9a7958dc069a1af4348495a9803b73b8312213b0a09199f91ee6f1bce69832","src/lib.rs":"6394a6e752f6c43251533e1086530568d253299909a90c965ec69ac23fbb9cfa","src/manager.rs":"621cbb3eebcb21fa85368122ba0fa8c721dd399334ca66813b795b396899ee81","src/readwrite.rs":"c0eb9f5cb146583a0a9f96efceddcedbecb38b1e9254e2554e8e15a991065ba5","src/value.rs":"bb7f16f838d865559ea319165a167207ee94df501317ef7f3035146a1631cd71","tests/manager.rs":"ebc8a9d6e55b1bc0c0699341141de2ce13e1306386ce5677a0eb4eb749f21d54"},"package":"21983ae9330b1e1cb1d01868229618a3c7cc5134955f0dc1a86a0a1886f3acb7"}
|
||||
{"files":{".appveyor.yml":"64ac2899deda9060b9665cc8f58c3b3509c0c426d618e221ff4f2cb47a3201d5",".rustfmt.toml":"b484c99708d8cdb01be0ef680a15b8897112942d041fc656fc5622816b6b3412",".travis.yml":"dfdacfeafbc68d1bb8670ffe6484ab6d5077c559dfeee41b4aec68acf1ff81bc","Cargo.toml":"d056c9e3d80dc0b35bba66382a80688612e4c49e6f1e261d024edb31093ed5fe","LICENSE":"cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30","README.md":"9dc24375b49fef42f35dec42e316e21827d7337622f9e7cf36243cd28808797a","examples/README.md":"143767fc145bf167ce269a65138cb3f7086cb715b8bc4f73626da82966e646f4","examples/iterator.rs":"112d21743156cc86292b7ee2e1fe230e2531a4b14b62dd57c6fbc8e56bea775f","examples/simple-store.rs":"d36887921364bc36fe925ea8209b71a88a9ccca4775d502134b6c68e81372e88","run-all-examples.sh":"7f9d11d01017f77e1c9d26e3e82dfca8c6930deaec85e864458e33a7fa267de0","src/env.rs":"bbbf8f09f2529f7953d3db96283a6b59bbe66e2f320b9aa768e97b7f1d20b4c5","src/error.rs":"495112ac06104c4f83e033604a6121cb2e12140cf6450d38d8a7c8d9f5fea874","src/integer.rs":"ba9a7958dc069a1af4348495a9803b73b8312213b0a09199f91ee6f1bce69832","src/lib.rs":"6394a6e752f6c43251533e1086530568d253299909a90c965ec69ac23fbb9cfa","src/manager.rs":"621cbb3eebcb21fa85368122ba0fa8c721dd399334ca66813b795b396899ee81","src/readwrite.rs":"c0eb9f5cb146583a0a9f96efceddcedbecb38b1e9254e2554e8e15a991065ba5","src/value.rs":"bb7f16f838d865559ea319165a167207ee94df501317ef7f3035146a1631cd71","tests/manager.rs":"ebc8a9d6e55b1bc0c0699341141de2ce13e1306386ce5677a0eb4eb749f21d54"},"package":"663e50c3b2454387726a83b01629892824dcf113c0471841ea4bc9b5929eb75e"}
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
[package]
|
||||
name = "rkv"
|
||||
version = "0.4.1"
|
||||
version = "0.5.1"
|
||||
authors = ["Richard Newman <rnewman@twinql.com>"]
|
||||
description = "a simple, humane, typed Rust interface to LMDB"
|
||||
homepage = "https://github.com/mozilla/rkv"
|
||||
|
@ -38,7 +38,7 @@ version = "1.0"
|
|||
[dependencies.lmdb-rkv]
|
||||
version = "0.8"
|
||||
|
||||
[dependencies.new-ordered-float]
|
||||
[dependencies.ordered-float]
|
||||
version = "1.0"
|
||||
|
||||
[dependencies.serde]
|
||||
|
@ -48,7 +48,7 @@ version = "1.0"
|
|||
version = "1.7.0"
|
||||
|
||||
[dependencies.uuid]
|
||||
version = "0.5"
|
||||
version = "0.6"
|
||||
[dev-dependencies.byteorder]
|
||||
version = "1"
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
{"files":{".travis.yml":"29bcc195f1cc7ef3e622fa81cc0154eb91760d22d5a3f108d228bf6c9bc60b6c","Cargo.toml":"4d8d751780a783658b4e264c6b365385337606e78d7ce12c71a41f63d33f48eb","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"af93d296b7d1347a0bdb2381e684e1799354cd4d7a079321c583a628086e175c","benches/parse_str.rs":"625a29dab53768392428a7ab69c81ce25965a73b7971f575999f9ad1f4ee12a2","src/lib.rs":"0d3edb152752eb53e7d7c2b54584b9e63411b0ab51f01b2444175d870b8beed1","src/rustc_serialize.rs":"5cb4ff0bb906b937e3f4cd854a14a9e9fbf57054db23874fbf2cf69e7f14bf9e","src/serde.rs":"7268965262403e99dc22f32bbbe641d5cf68af57bc502f288fa5eeb47e04a5c1","src/std_support.rs":"bd1db679cf0299cb5f60501ccbe59ea14be9224ef6fbb740069c5e136d311def"},"package":"bcc7e3b898aa6f6c08e5295b6c89258d1331e9ac578cc992fb818759951bdc22"}
|
|
@ -1,35 +0,0 @@
|
|||
language: rust
|
||||
rust:
|
||||
- stable
|
||||
- beta
|
||||
- nightly
|
||||
sudo: false
|
||||
before_script:
|
||||
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
|
||||
script:
|
||||
- cargo build --verbose --features "$FEATURES"
|
||||
- cargo test --verbose --features "$FEATURES"
|
||||
- |
|
||||
[ $TRAVIS_RUST_VERSION != nightly ] || (
|
||||
cargo bench --features "$FEATURES"
|
||||
)
|
||||
- cargo doc --no-deps --features "$FEATURES"
|
||||
after_success:
|
||||
- travis-cargo --only nightly doc-upload
|
||||
env:
|
||||
global:
|
||||
secure: "HzcZYuf80pByt4J3OM+sfXg5dGPQjFTPfLYR907wfi8FD6mJu5yYbgPF4agz9sdnnNrtnmlghZ5WFljrl49oNC6RhcSc6YVmiRKs4DabMKKr3v9zZy1i2KuQ323cGpwUIVpq7+u8/vQAYPwRUPzZrVw57y5KKqEHbn2T85yFdqo="
|
||||
|
||||
matrix:
|
||||
- FEATURES=""
|
||||
- FEATURES="rustc-serialize"
|
||||
- FEATURES="serde"
|
||||
- FEATURES="use_std"
|
||||
- FEATURES="v1"
|
||||
- FEATURES="v3"
|
||||
- FEATURES="v4"
|
||||
- FEATURES="v5"
|
||||
- FEATURES="rustc-serialize serde v1 v3 v4 v5 use_std"
|
||||
notifications:
|
||||
email:
|
||||
on_success: never
|
|
@ -1,30 +0,0 @@
|
|||
[package]
|
||||
|
||||
name = "uuid"
|
||||
version = "0.5.1"
|
||||
authors = ["The Rust Project Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/rust-lang/uuid"
|
||||
homepage = "https://github.com/rust-lang/uuid"
|
||||
documentation = "https://doc.rust-lang.org/uuid"
|
||||
description = """
|
||||
A library to generate and parse UUIDs.
|
||||
"""
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
||||
[dependencies]
|
||||
rustc-serialize = { version = "0.3", optional = true }
|
||||
serde = { version = "1.0", optional = true }
|
||||
rand = { version = "0.3", optional = true }
|
||||
sha1 = { version = "0.2", optional = true }
|
||||
md5 = { version = "0.3", optional = true }
|
||||
|
||||
[features]
|
||||
use_std = []
|
||||
v1 = ["rand"]
|
||||
v3 = ["md5"]
|
||||
v4 = ["rand"]
|
||||
v5 = ["sha1"]
|
|
@ -1,201 +0,0 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -1,25 +0,0 @@
|
|||
Copyright (c) 2014 The Rust Project Developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
|
@ -1,105 +0,0 @@
|
|||
uuid
|
||||
====
|
||||
|
||||
[![Build Status](https://travis-ci.org/rust-lang-nursery/uuid.svg?branch=master)](https://travis-ci.org/rust-lang-nursery/uuid)
|
||||
|
||||
A Rust library to generate and parse UUIDs.
|
||||
|
||||
Provides support for Universally Unique Identifiers (UUIDs). A UUID is a unique
|
||||
128-bit number, stored as 16 octets. UUIDs are used to assign unique identifiers
|
||||
to entities without requiring a central allocating authority.
|
||||
|
||||
They are particularly useful in distributed systems, though can be used in
|
||||
disparate areas, such as databases and network protocols. Typically a UUID is
|
||||
displayed in a readable string form as a sequence of hexadecimal digits,
|
||||
separated into groups by hyphens.
|
||||
|
||||
The uniqueness property is not strictly guaranteed, however for all practical
|
||||
purposes, it can be assumed that an unintentional collision would be extremely
|
||||
unlikely.
|
||||
|
||||
[Documentation](https://doc.rust-lang.org/uuid)
|
||||
|
||||
## Usage
|
||||
|
||||
Add this to your `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
uuid = "0.5"
|
||||
```
|
||||
|
||||
and this to your crate root:
|
||||
|
||||
```rust
|
||||
extern crate uuid;
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
To parse a simple UUID, then print the version and urn string format:
|
||||
|
||||
```rust
|
||||
extern crate uuid;
|
||||
use uuid::Uuid;
|
||||
|
||||
fn main() {
|
||||
let my_uuid = Uuid::parse_str("936DA01F9ABD4d9d80C702AF85C822A8").unwrap();
|
||||
println!("Parsed a version {} UUID.", my_uuid.get_version_num());
|
||||
println!("{}", my_uuid);
|
||||
}
|
||||
```
|
||||
|
||||
The library supports 5 versions of UUID:
|
||||
|
||||
Name | Version
|
||||
---------|----------
|
||||
Mac | Version 1: MAC address
|
||||
Dce | Version 2: DCE Security
|
||||
Md5 | Version 3: MD5 hash
|
||||
Random | Version 4: Random
|
||||
Sha1 | Version 5: SHA-1 hash
|
||||
|
||||
To create a new random (V4) UUID and print it out in hexadecimal form, first
|
||||
you'll need to change how you depend on `uuid`:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
uuid = { version = "0.5", features = ["v4"] }
|
||||
```
|
||||
|
||||
Next, you'll write:
|
||||
|
||||
```rust
|
||||
extern crate uuid;
|
||||
use uuid::Uuid;
|
||||
|
||||
fn main() {
|
||||
let my_uuid = Uuid::new_v4();
|
||||
println!("{}", my_uuid);
|
||||
}
|
||||
```
|
||||
|
||||
To create a new sha1-hash based (V5) UUID and print it out in hexadecimal form,
|
||||
you'll also need to change how you depend on `uuid`:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
uuid = { version = "0.5", features = ["v5"] }
|
||||
```
|
||||
|
||||
Next, you'll write:
|
||||
|
||||
```rust
|
||||
extern crate uuid;
|
||||
use uuid::Uuid;
|
||||
|
||||
fn main() {
|
||||
let my_uuid = Uuid::new_v5(&uuid::NAMESPACE_DNS, "foo");
|
||||
println!("{}", my_uuid);
|
||||
}
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
[Wikipedia: Universally Unique Identifier](https://en.wikipedia.org/wiki/Universally_unique_identifier)
|
|
@ -1,87 +0,0 @@
|
|||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
extern crate uuid;
|
||||
|
||||
use test::Bencher;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[bench]
|
||||
fn bench_parse(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let _ = Uuid::parse_str("");
|
||||
let _ = Uuid::parse_str("!");
|
||||
let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E45");
|
||||
let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-BBF-329BF39FA1E4");
|
||||
let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-BGBF-329BF39FA1E4");
|
||||
let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BFF329BF39FA1E4");
|
||||
let _ = Uuid::parse_str("F9168C5E-CEB2-4faa");
|
||||
let _ = Uuid::parse_str("F9168C5E-CEB2-4faaXB6BFF329BF39FA1E4");
|
||||
let _ = Uuid::parse_str("F9168C5E-CEB-24fa-eB6BFF32-BF39FA1E4");
|
||||
let _ = Uuid::parse_str("01020304-1112-2122-3132-41424344");
|
||||
let _ = Uuid::parse_str("67e5504410b1426f9247bb680e5fe0c88");
|
||||
let _ = Uuid::parse_str("67e5504410b1426f9247bb680e5fe0cg8");
|
||||
let _ = Uuid::parse_str("67e5504410b1426%9247bb680e5fe0c8");
|
||||
|
||||
// Valid
|
||||
let _ = Uuid::parse_str("00000000000000000000000000000000");
|
||||
let _ = Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8");
|
||||
let _ = Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8");
|
||||
let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4");
|
||||
let _ = Uuid::parse_str("67e5504410b1426f9247bb680e5fe0c8");
|
||||
let _ = Uuid::parse_str("01020304-1112-2122-3132-414243444546");
|
||||
let _ = Uuid::parse_str("urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8");
|
||||
|
||||
// Nil
|
||||
let _ = Uuid::parse_str("00000000000000000000000000000000");
|
||||
let _ = Uuid::parse_str("00000000-0000-0000-0000-000000000000");
|
||||
|
||||
// Test error reporting
|
||||
let _ = Uuid::parse_str("67e5504410b1426f9247bb680e5fe0c");
|
||||
let _ = Uuid::parse_str("67e550X410b1426f9247bb680e5fe0cd");
|
||||
let _ = Uuid::parse_str("67e550-4105b1426f9247bb680e5fe0c");
|
||||
let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF1-02BF39FA1E4");
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_parse_invalid_len(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-BBF-329BF39FA1E4");
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_parse_invalid_character(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-BGBF-329BF39FA1E4");
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_parse_invalid_group_len(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let _ = Uuid::parse_str("01020304-1112-2122-3132-41424344");
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_parse_invalid_groups(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BFF329BF39FA1E4");
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_valid_hyphenated(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let _ = Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8");
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_valid_short(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let _ = Uuid::parse_str("67e5504410b1426f9247bb680e5fe0c8");
|
||||
});
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,34 +0,0 @@
|
|||
extern crate rustc_serialize;
|
||||
extern crate std;
|
||||
|
||||
use self::std::prelude::v1::*;
|
||||
use self::rustc_serialize::{Encoder, Encodable, Decoder, Decodable};
|
||||
|
||||
use Uuid;
|
||||
|
||||
impl Encodable for Uuid {
|
||||
fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
|
||||
e.emit_str(&self.hyphenated().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for Uuid {
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<Uuid, D::Error> {
|
||||
let string = try!(d.read_str());
|
||||
string.parse::<Uuid>().map_err(|err| d.error(&err.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::rustc_serialize::json;
|
||||
use Uuid;
|
||||
|
||||
#[test]
|
||||
fn test_serialize_round_trip() {
|
||||
let u = Uuid::parse_str("F9168C5E-CEB2-4FAA-B6BF-329BF39FA1E4").unwrap();
|
||||
let s = json::encode(&u).unwrap();
|
||||
let u2 = json::decode(&s).unwrap();
|
||||
assert_eq!(u, u2);
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
extern crate serde;
|
||||
extern crate std;
|
||||
|
||||
use self::std::fmt;
|
||||
use self::std::prelude::v1::*;
|
||||
use self::serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
use Uuid;
|
||||
|
||||
impl Serialize for Uuid {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
serializer.collect_str(&self.hyphenated())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for Uuid {
|
||||
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||
struct UuidVisitor;
|
||||
|
||||
impl<'vi> de::Visitor<'vi> for UuidVisitor {
|
||||
type Value = Uuid;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "a UUID string")
|
||||
}
|
||||
|
||||
fn visit_str<E: de::Error>(self, value: &str) -> Result<Uuid, E> {
|
||||
value.parse::<Uuid>().map_err(|e| E::custom(e.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_str(UuidVisitor)
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
extern crate std;
|
||||
|
||||
use ParseError;
|
||||
|
||||
impl std::error::Error for ParseError {
|
||||
fn description(&self) -> &str {
|
||||
"UUID parse error"
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ rsdparsa_capi = { path = "../../../../media/webrtc/signaling/src/sdp/rsdparsa_ca
|
|||
log = {version = "0.4", features = ["release_max_level_info"]}
|
||||
env_logger = {version = "0.5", default-features = false} # disable `regex` to reduce code size
|
||||
cose-c = { version = "0.1.5" }
|
||||
rkv = "0.4"
|
||||
rkv = "0.5"
|
||||
jsrust_shared = { path = "../../../../js/src/rust/shared", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
|
|
Загрузка…
Ссылка в новой задаче