Add the std / no_std feature.

This commit is contained in:
Dimitri Sabadie 2018-08-09 01:23:45 +02:00
parent a24826b879
commit 393a8c2f15
4 changed files with 34 additions and 8 deletions

View File

@ -19,3 +19,6 @@ script:
- echo "Testing feature serialization"
- cargo build --verbose --features serialization
- cargo test --verbose --features serialization
- echo "Testing without std"
- cargo build --verbose --no-default-features
- cargo test --verbose --no-default-features

View File

@ -18,8 +18,9 @@ is-it-maintained-open-issues = { repository = "phaazon/splines" }
maintenance = { status = "actively-developed" }
[features]
default = []
default = ["std"]
serialization = ["serde", "serde_derive"]
std = []
[dependencies]
cgmath = "0.16"

View File

@ -9,6 +9,11 @@ Feel free to dig in the [online documentation](https://docs.rs/splines) for furt
This crate has features! Heres a comprehensive list of what you can enable:
- **Serialization / deserialization**
- **Serialization / deserialization.**
+ This feature implements both the `Serialize` and `Deserialize` traits from `serde`.
+ Enable with the feature `"serialization"`.
+ Enable with the `"serialization"` feature.
- **Standard library / no stdandard library**
+ Its possible to compile against the standard library or go on your own without it.
+ Compiling with the standard library is enabled by default.
+ Use `defaut-features = []` in your `Cargo.toml` to disable.
+ Enable explicitly with the `"std"` feataure.

View File

@ -76,9 +76,20 @@
//!
//! So heres a list of currently supported features and how to enable them:
//!
//! - **Serialization / deserialization**
//! - **Serialization / deserialization.**
//! + This feature implements both the `Serialize` and `Deserialize` traits from `serde`.
//! + Enable with the feature `"serialization"`.
//! + Enable with the `"serialization"` feature.
//! - **Standard library / no stdandard library**
//! + Its possible to compile against the standard library or go on your own without it.
//! + Compiling with the standard library is enabled by default.
//! + Use `defaut-features = []` in your `Cargo.toml` to disable.
//! + Enable explicitly with the `"std"` feataure.
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
// on no_std, we also need the alloc crate for Vec
#[cfg(not(feature = "std"))] extern crate alloc;
extern crate cgmath;
@ -86,9 +97,15 @@ extern crate cgmath;
#[cfg(feature = "serialization")] #[macro_use] extern crate serde_derive;
use cgmath::{InnerSpace, Quaternion, Vector2, Vector3, Vector4};
use std::cmp::Ordering;
use std::f32::consts;
use std::ops::{Add, Div, Mul, Sub};
#[cfg(feature = "std")] use std::cmp::Ordering;
#[cfg(feature = "std")] use std::f32::consts;
#[cfg(feature = "std")] use std::ops::{Add, Div, Mul, Sub};
#[cfg(not(feature = "std"))] use alloc::vec::Vec;
#[cfg(not(feature = "std"))] use core::cmp::Ordering;
#[cfg(not(feature = "std"))] use core::f32::consts;
#[cfg(not(feature = "std"))] use core::ops::{Add, Div, Mul, Sub};
/// A spline control point.
///