Skip to content

Replace no_std feature with std feature #48

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

Merged
merged 5 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
rust: [stable]
FEATURES: ['', 'from_str', 'no_std']
FEATURES: ['', 'from_str', 'std']

include:
# Test nightly but don't fail
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: build
args: --target=${{ matrix.TARGET }} --features no_std
args: --target=${{ matrix.TARGET }}

fmt:
runs-on: ubuntu-latest
Expand All @@ -83,7 +83,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
FEATURES: ['', 'from_str', 'no_std']
FEATURES: ['', 'from_str', 'std']
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

- Replaced the `no_std` feature with an additive `std` feature, fixing problems with serde serialization on `no_std` targets.

## [0.10.4]

### Added
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ license = "MIT"
readme = "README.md"

[features]
no_std = [ "libm" ]
from_str = ["regex"]
std = []
from_str = ["regex", "std"]

[dependencies]
serde = { version = "1.0", optional = true, features = ["derive"] }
serde = { version = "1.0", optional = true, default-features = false, features = ["derive"] }
regex = { version = "1", optional = true }
libm = { version = "0.2", optional = true }
libm = { version = "0.2" }
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ fn main() {

The crate contains few features to disable or enable certain functionalities:

* no_std
* Removes functionality that Rust std library provides
* `std`
* Enables functionality that Rust standard library provides instead of using `libm` for some math functions
* from_str
* Allows creating measurement units from string input

Expand Down
14 changes: 7 additions & 7 deletions src/angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,43 +47,43 @@ impl Angle {
}

/// Calculate the cosine of this angle
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
pub fn cos(&self) -> f64 {
self.radians.cos()
}

/// Calculate the sine of this angle
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
pub fn sin(&self) -> f64 {
self.radians.sin()
}

/// Calculate the sine and cosine of this angle
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
pub fn sin_cos(&self) -> (f64, f64) {
self.radians.sin_cos()
}

/// Calculate the tangent of this angle
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
pub fn tan(&self) -> f64 {
self.radians.tan()
}

/// Calculate the arcsine of a number
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
pub fn asin(num: f64) -> Self {
Angle::from_radians(num.asin())
}

/// Calculate the arccosine of a number
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
pub fn acos(num: f64) -> Self {
Angle::from_radians(num.acos())
}

/// Calculate the arctangent of a number
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
pub fn atan(num: f64) -> Self {
Angle::from_radians(num.atan())
}
Expand Down
12 changes: 6 additions & 6 deletions src/humidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Humidity {
/// Calculates Dewpoint from humidity and air temperature using the Magnus-Tetens
/// approximation, with coefficients derived by Alduchov and Eskridge (1996). The formulas assume
// standard atmospheric pressure.
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
pub fn as_dewpoint(&self, temp: Temperature) -> Temperature {
let humidity = self.relative_humidity / 100.0;
let celsius = temp.as_celsius();
Expand All @@ -81,7 +81,7 @@ impl Humidity {
/// Calculates Dewpoint from humidity and air temperature using the Magnus-Tetens
/// approximation, with coefficients derived by Alduchov and Eskridge (1996). The formulas assume
// standard atmospheric pressure.
#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
pub fn as_dewpoint(&self, temp: Temperature) -> Temperature {
let humidity = self.relative_humidity / 100.0;
let celsius = temp.as_celsius();
Expand All @@ -94,7 +94,7 @@ impl Humidity {
/// Calculates the actual vapour pressure in the air, based on the air temperature and humidity
/// at standard atmospheric pressure (1013.25 mb), using the Buck formula (accurate to +/- 0.02%
/// between 0 deg C and 50 deg C)
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
pub fn as_vapor_pressure(&self, temp: Temperature) -> Pressure {
let temp = temp.as_celsius();
let saturation_vapor_pressure =
Expand All @@ -105,7 +105,7 @@ impl Humidity {
/// Calculates the actual vapour pressure in the air, based on the air temperature and humidity
/// at standard atmospheric pressure (1013.25 mb), using the Buck formula (accurate to +/- 0.02%
/// between 0 deg C and 50 deg C)
#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
pub fn as_vapor_pressure(&self, temp: Temperature) -> Pressure {
let temp = temp.as_celsius();
let saturation_vapor_pressure =
Expand All @@ -125,7 +125,7 @@ impl Humidity {
/// Calculates humidity from dewpoint and air temperature using the Magnus-Tetens
/// Approximation, with coefficients derived by Alduchov and Eskridge (1996). The formulas assume
// standard atmospheric pressure.
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
pub fn from_dewpoint(dewpoint: Temperature, temp: Temperature) -> Humidity {
let dewpoint = dewpoint.as_celsius();
let temp = temp.as_celsius();
Expand All @@ -138,7 +138,7 @@ impl Humidity {
/// Calculates humidity from dewpoint and air temperature using the Magnus-Tetens
/// Approximation, with coefficients derived by Alduchov and Eskridge (1996). The formulas assume
// standard atmospheric pressure.
#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
pub fn from_dewpoint(dewpoint: Temperature, temp: Temperature) -> Humidity {
let dewpoint = dewpoint.as_celsius();
let temp = temp.as_celsius();
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
//! by an Area to get a Pressure.

#![deny(warnings, missing_docs)]
#![cfg_attr(feature = "no_std", no_std)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
use core as std;
#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
use core::time;

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
use std::time;

#[cfg(feature = "serde")]
Expand Down