Skip to content

"std" feature #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ version = "0.1.41"
readme = "README.md"

[dependencies]

[features]
default = ["std"]
std = []
3 changes: 3 additions & 0 deletions ci/rustup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ set -ex
export TRAVIS_RUST_VERSION
for TRAVIS_RUST_VERSION in 1.8.0 stable beta nightly; do
run="rustup run $TRAVIS_RUST_VERSION"
if [ "$TRAVIS_RUST_VERSION" = 1.8.0 ]; then
$run cargo generate-lockfile
fi
$run cargo build --verbose
$run $PWD/ci/test_full.sh
done
10 changes: 8 additions & 2 deletions ci/test_full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ set -ex

echo Testing num-traits on rustc ${TRAVIS_RUST_VERSION}

# num-integer should build and test everywhere.
# num-traits should build and test everywhere.
cargo build --verbose
cargo test --verbose

# We have no features to test...
# It should build with minimal features too.
cargo build --no-default-features
cargo test --no-default-features

# num-traits with explicit std feature
cargo build --verbose --no-default-features --features="$feature"
cargo test --verbose --no-default-features --features="$feature"
8 changes: 4 additions & 4 deletions src/bounds.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{usize, u8, u16, u32, u64};
use std::{isize, i8, i16, i32, i64};
use std::{f32, f64};
use std::num::Wrapping;
use core::{usize, u8, u16, u32, u64};
use core::{isize, i8, i16, i32, i64};
use core::{f32, f64};
use core::num::Wrapping;

/// Numbers which have upper and lower bounds
pub trait Bounded {
Expand Down
13 changes: 7 additions & 6 deletions src/cast.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::mem::size_of;
use std::num::Wrapping;
use core::mem::size_of;
use core::num::Wrapping;

use identities::Zero;
use bounds::Bounded;
use float::Float;

/// A generic trait for converting a value to a number.
pub trait ToPrimitive {
Expand Down Expand Up @@ -226,8 +227,8 @@ macro_rules! impl_to_primitive_float_to_float {
// Make sure the value is in range for the cast.
// NaN and +-inf are cast as they are.
let n = $slf as f64;
let max_value: $DstT = ::std::$DstT::MAX;
if !n.is_finite() || (-max_value as f64 <= n && n <= max_value as f64) {
let max_value: $DstT = ::core::$DstT::MAX;
if !Float::is_finite(n) || (-max_value as f64 <= n && n <= max_value as f64) {
Some($slf as $DstT)
} else {
None
Expand Down Expand Up @@ -454,8 +455,8 @@ impl<T: NumCast> NumCast for Wrapping<T> {

#[test]
fn to_primitive_float() {
use std::f32;
use std::f64;
use core::f32;
use core::f64;

let f32_toolarge = 1e39f64;
assert_eq!(f32_toolarge.to_f32(), None);
Expand Down
Loading