Skip to content

Commit

Permalink
Revert "alloc" to "std" feature
Browse files Browse the repository at this point in the history
Features should be additive. This change was originally made due to a
misunderstanding about what serde's "alloc" feature was for. It is not
necessary, so this change is being reverted.
  • Loading branch information
jhpratt committed Jan 21, 2020
1 parent 7d7fbad commit 9ec2862
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 115 deletions.
23 changes: 14 additions & 9 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,28 @@ jobs:
toolchain: ${{ matrix.rust }}
override: true

# deprecated
- name: Run `cargo check --features alloc`
# ensure `#![no_std]` support
- name: Run `cargo check --no-default-features`
uses: actions-rs/cargo@v1
with:
command: check
args: --no-default-features
if: matrix.rust != '1.34.0' # alloc is unstable in 1.34

# std, serde, deprecated
- name: Run `cargo check --features serde`
# `#![no_std]` and serde
- name: Run `cargo check --no-default-features --features serde`
uses: actions-rs/cargo@v1
with:
command: check
args: --no-default-features --features serde
if: matrix.rust != '1.34.0' # alloc is unstable in 1.34

# std, deprecated
- name: Run `cargo check`
# everything
- name: Run `cargo check --all-features`
uses: actions-rs/cargo@v1
with:
command: check
args: --all-features

test:
name: Test suite
Expand All @@ -64,17 +66,20 @@ jobs:
toolchain: ${{ matrix.rust }}
override: true

- name: Run `cargo test --features alloc`
# `#![no_std]` support
- name: Run `cargo test --no-default-features`
uses: actions-rs/cargo@v1
with:
command: test
args: --features alloc
args: --no-default-features
if: matrix.rust != '1.34.0' # alloc is unstable in 1.34

- name: Run `cargo test`
# everything
- name: Run `cargo test --all-features`
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features

fmt:
name: Formatting
Expand Down
15 changes: 6 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "time"
version = "0.2.3"
version = "0.2.4"
authors = ["Jacob Pratt <the.z.cuber@gmail.com>"]
edition = "2018"
repository = "https://github.com/time-rs/time"
Expand All @@ -12,21 +12,18 @@ license = "MIT OR Apache-2.0"
description = "Date and time library. Fully interoperable with the standard library. Mostly compatible with #![no_std]."

[package.metadata.docs.rs]
features = ["deprecated", "panicking-api", "serde"]
all-features = true

[features]
default = ["deprecated"]
default = ["deprecated", "std"]
deprecated = []
alloc = ["serde/alloc"]
panicking-api = []
std = []

[dependencies]
rustversion = "1"
serde = { version = "1", optional = true, default-features = false, features = ["derive"] }
time-macros = { version = "0.1", path = "time-macros" }
rustversion = "1"

[workspace]
members = [
"time-macros",
"time-macros-impl",
]
members = ["time-macros", "time-macros-impl"]
6 changes: 3 additions & 3 deletions src/date.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "alloc")]
#[cfg(not(feature = "std"))]
use crate::alloc_prelude::*;
use crate::{
format::parse::{parse, ParseError, ParseResult, ParsedItems},
Expand Down Expand Up @@ -274,8 +274,8 @@ impl Date {
/// assert!(Date::today().year() >= 2019);
/// ```
#[inline(always)]
#[cfg(not(feature = "alloc"))]
#[cfg_attr(doc, doc(cfg(not(feature = "alloc"))))]
#[cfg(feature = "std")]
#[cfg_attr(doc, doc(cfg(feature = "std")))]
pub fn today() -> Self {
PrimitiveDateTime::now().date()
}
Expand Down
14 changes: 7 additions & 7 deletions src/duration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[allow(unused_imports)]
use crate::shim::*;
#[cfg(not(feature = "alloc"))]
#[cfg(feature = "std")]
use crate::Instant;
use crate::{
ConversionRangeError,
Expand Down Expand Up @@ -247,7 +247,7 @@ impl Duration {

/// Convert the existing `Duration` to a `std::time::Duration` and its sign.
#[inline(always)]
#[cfg(not(feature = "alloc"))]
#[cfg(feature = "std")]
pub(crate) fn sign_abs_std(self) -> (Sign, StdDuration) {
(
self.sign(),
Expand Down Expand Up @@ -749,8 +749,8 @@ impl Duration {
/// Runs a closure, returning the duration of time it took to run. The
/// return value of the closure is provided in the second part of the tuple.
#[inline(always)]
#[cfg(not(feature = "alloc"))]
#[cfg_attr(doc, doc(cfg(not(feature = "alloc"))))]
#[cfg(feature = "std")]
#[cfg_attr(doc, doc(cfg(feature = "std")))]
pub fn time_fn<T>(f: impl FnOnce() -> T) -> (Self, T) {
let start = Instant::now();
let return_value = f();
Expand Down Expand Up @@ -852,7 +852,7 @@ impl Duration {
}

#[inline(always)]
#[cfg(not(feature = "alloc"))]
#[cfg(feature = "std")]
#[deprecated(since = "0.2.0", note = "Use the `time_fn` function")]
pub fn span<F: FnOnce()>(f: F) -> Self {
Self::time_fn(f).0
Expand Down Expand Up @@ -1559,7 +1559,7 @@ mod test {
}

#[test]
#[cfg(not(feature = "alloc"))]
#[cfg(feature = "std")]
fn time_fn() {
let (time, value) = Duration::time_fn(|| {
std::thread::sleep(100.std_milliseconds());
Expand Down Expand Up @@ -1702,7 +1702,7 @@ mod test {
duration -= 500.milliseconds();
assert_eq!(duration, 1.seconds());

#[cfg(not(feature = "alloc"))]
#[cfg(feature = "std")]
{
let mut duration = 1.std_seconds();
assert_panics!(duration -= 2.seconds());
Expand Down
10 changes: 4 additions & 6 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#[cfg(feature = "alloc")]
#[cfg(not(feature = "std"))]
use crate::alloc_prelude::*;
use crate::format::ParseError;
use core::fmt;
#[cfg(not(feature = "alloc"))]
use std::boxed::Box;

/// A unified error type for anything returned by a method in the time crate.
///
Expand Down Expand Up @@ -35,7 +33,7 @@ impl fmt::Display for Error {
}
}

#[cfg(not(feature = "alloc"))]
#[cfg(feature = "std")]
impl std::error::Error for Error {}

/// An error type indicating that a conversion failed because the target type
Expand Down Expand Up @@ -66,7 +64,7 @@ impl fmt::Display for ConversionRangeError {
}
}

#[cfg(not(feature = "alloc"))]
#[cfg(feature = "std")]
impl std::error::Error for ConversionRangeError {}

impl From<ConversionRangeError> for Error {
Expand Down Expand Up @@ -127,7 +125,7 @@ impl From<ComponentRangeError> for Error {
}
}

#[cfg(not(feature = "alloc"))]
#[cfg(feature = "std")]
impl std::error::Error for ComponentRangeError {}

impl From<ParseError> for Error {
Expand Down
2 changes: 1 addition & 1 deletion src/format/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{
},
Padding, ParseError, ParseResult, ParsedItems,
};
#[cfg(feature = "alloc")]
#[cfg(not(feature = "std"))]
use crate::alloc_prelude::*;
use crate::{shim::*, Date, Sign, Weekday};
use core::{
Expand Down
2 changes: 1 addition & 1 deletion src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub(crate) mod parse;
pub(crate) mod parse_items;
pub(crate) mod time;

#[cfg(feature = "alloc")]
#[cfg(not(feature = "std"))]
use crate::alloc_prelude::*;
use crate::{Date, Time, UtcOffset};
use core::fmt::{self, Display, Formatter};
Expand Down
13 changes: 4 additions & 9 deletions src/format/parse.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
//! Parsing for various types.

use super::{parse_fmt_string, FormatItem, Padding, Specifier};
#[cfg(not(feature = "std"))]
use crate::alloc_prelude::*;
use crate::{shim::*, ComponentRangeError, UtcOffset, Weekday};
use core::{
fmt::{self, Display, Formatter},
num::{NonZeroU16, NonZeroU8},
ops::{Bound, RangeBounds},
str::FromStr,
};
#[cfg(not(feature = "alloc"))]
use std::error::Error;

#[cfg(feature = "alloc")]
use alloc::boxed::Box;
#[cfg(not(feature = "alloc"))]
use std::boxed::Box;

/// Helper type to avoid repeating the error type.
pub(crate) type ParseResult<T> = Result<T, ParseError>;
Expand Down Expand Up @@ -105,8 +100,8 @@ impl Display for ParseError {
}
}

#[cfg(not(feature = "alloc"))]
impl Error for ParseError {}
#[cfg(feature = "std")]
impl std::error::Error for ParseError {}

/// A value representing a time that is either "AM" or "PM".
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion src/format/parse_items.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Parse formats used in the `format` and `parse` methods.

#[cfg(feature = "alloc")]
#[cfg(not(feature = "std"))]
use crate::alloc_prelude::*;
use crate::format::{FormatItem, Padding, Specifier};

Expand Down
2 changes: 1 addition & 1 deletion src/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::time::Instant as StdInstant;
///
/// This implementation allows for operations with signed [`Duration`]s, but is
/// otherwise identical to [`std::time::Instant`].
#[cfg_attr(doc, doc(cfg(not(feature = "alloc"))))]
#[cfg_attr(doc, doc(cfg(feature = "std")))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Instant {
/// Inner representation, using `std::time::Instant`.
Expand Down
Loading

0 comments on commit 9ec2862

Please sign in to comment.