Test against serde with no features in both std and no-std
This commit is contained in:
parent
e5bbc94c3b
commit
a09f9ba2a8
|
@ -27,8 +27,6 @@ name = "chrono"
|
||||||
default = ["clock", "std"]
|
default = ["clock", "std"]
|
||||||
alloc = []
|
alloc = []
|
||||||
std = []
|
std = []
|
||||||
serde_alloc = ["serde/alloc"]
|
|
||||||
serde_std = ["serde/std"]
|
|
||||||
clock = ["time", "std"]
|
clock = ["time", "std"]
|
||||||
wasmbind = ["wasm-bindgen", "js-sys"]
|
wasmbind = ["wasm-bindgen", "js-sys"]
|
||||||
|
|
||||||
|
@ -44,9 +42,9 @@ wasm-bindgen = { version = "0.2", optional = true }
|
||||||
js-sys = { version = "0.3", optional = true } # contains FFI bindings for the JS Date API
|
js-sys = { version = "0.3", optional = true } # contains FFI bindings for the JS Date API
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_json = { version = "1" }
|
serde_json = { version = "1", default-features = false }
|
||||||
serde_derive = { version = "1" }
|
serde_derive = { version = "1", default-features = false }
|
||||||
bincode = { version = "0.8.0" }
|
bincode = { version = "1.1.0" }
|
||||||
num-iter = { version = "0.1.35", default-features = false }
|
num-iter = { version = "0.1.35", default-features = false }
|
||||||
doc-comment = "0.3"
|
doc-comment = "0.3"
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,9 @@ build_and_test_nonwasm() {
|
||||||
channel build -v --no-default-features --features std,serde,rustc-serialize
|
channel build -v --no-default-features --features std,serde,rustc-serialize
|
||||||
TZ=Asia/Katmandu channel test -v --no-default-features --features std,serde,rustc-serialize --lib
|
TZ=Asia/Katmandu channel test -v --no-default-features --features std,serde,rustc-serialize --lib
|
||||||
|
|
||||||
|
channel build -v --no-default-features --features 'serde'
|
||||||
|
TZ=UTC0 channel test -v --no-default-features --features 'serde' --lib
|
||||||
|
|
||||||
channel build -v --no-default-features --features 'alloc serde'
|
channel build -v --no-default-features --features 'alloc serde'
|
||||||
TZ=UTC0 channel test -v --no-default-features --features 'alloc serde' --lib
|
TZ=UTC0 channel test -v --no-default-features --features 'alloc serde' --lib
|
||||||
}
|
}
|
||||||
|
@ -151,7 +154,7 @@ build_core_test() {
|
||||||
channel_run rustup target add thumbv6m-none-eabi --toolchain "$CHANNEL"
|
channel_run rustup target add thumbv6m-none-eabi --toolchain "$CHANNEL"
|
||||||
(
|
(
|
||||||
cd ci/core-test
|
cd ci/core-test
|
||||||
channel build -v --features alloc --target thumbv6m-none-eabi
|
channel build -v --target thumbv6m-none-eabi
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -923,37 +923,12 @@ pub mod rustc_serialize {
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
pub mod serde {
|
pub mod serde {
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
// #[cfg(any(test, feature = "alloc"))]
|
|
||||||
// use alloc::format;
|
|
||||||
use super::DateTime;
|
use super::DateTime;
|
||||||
#[cfg(feature="clock")]
|
#[cfg(feature="clock")]
|
||||||
use offset::Local;
|
use offset::Local;
|
||||||
use offset::{LocalResult, TimeZone, Utc, FixedOffset};
|
use offset::{LocalResult, TimeZone, Utc, FixedOffset};
|
||||||
use serdelib::{ser, de};
|
use serdelib::{ser, de};
|
||||||
|
use {SerdeError, ne_timestamp};
|
||||||
enum SerdeError<V: fmt::Display, D: fmt::Display> {
|
|
||||||
NonExistent { timestamp: V },
|
|
||||||
Ambiguous { timestamp: V, min: D, max: D }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<V: fmt::Display, D: fmt::Display> fmt::Debug for SerdeError<V, D> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "ChronoSerdeError({})", self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// impl<V: fmt::Display, D: fmt::Debug> core::error::Error for SerdeError<V, D> {}
|
|
||||||
impl<V: fmt::Display, D: fmt::Display> fmt::Display for SerdeError<V, D> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
&SerdeError::NonExistent { ref timestamp } => write!(
|
|
||||||
f, "value is not a legal timestamp: {}", timestamp),
|
|
||||||
&SerdeError::Ambiguous { ref timestamp, ref min, ref max } => write!(
|
|
||||||
f, "value is an ambiguous timestamp: {}, could be either of {}, {}",
|
|
||||||
timestamp, min, max),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// try!-like function to convert a LocalResult into a serde-ish Result
|
// try!-like function to convert a LocalResult into a serde-ish Result
|
||||||
fn serde_from<T, E, V>(me: LocalResult<T>, ts: &V) -> Result<T, E>
|
fn serde_from<T, E, V>(me: LocalResult<T>, ts: &V) -> Result<T, E>
|
||||||
|
@ -964,7 +939,7 @@ pub mod serde {
|
||||||
{
|
{
|
||||||
match me {
|
match me {
|
||||||
LocalResult::None => Err(E::custom(
|
LocalResult::None => Err(E::custom(
|
||||||
SerdeError::NonExistent::<_, u8> { timestamp: ts })),
|
ne_timestamp(ts))),
|
||||||
LocalResult::Ambiguous(min, max) => Err(E::custom(
|
LocalResult::Ambiguous(min, max) => Err(E::custom(
|
||||||
SerdeError::Ambiguous { timestamp: ts, min: min, max: max })),
|
SerdeError::Ambiguous { timestamp: ts, min: min, max: max })),
|
||||||
LocalResult::Single(val) => Ok(val)
|
LocalResult::Single(val) => Ok(val)
|
||||||
|
|
35
src/lib.rs
35
src/lib.rs
|
@ -520,6 +520,41 @@ pub mod serde {
|
||||||
pub use super::datetime::serde::*;
|
pub use super::datetime::serde::*;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Until rust 1.18 there is no "pub(crate)" so to share this we need it in the root
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
enum SerdeError<V: fmt::Display, D: fmt::Display> {
|
||||||
|
NonExistent { timestamp: V },
|
||||||
|
Ambiguous { timestamp: V, min: D, max: D },
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Construct a [`SerdeError::NonExistent`]
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
fn ne_timestamp<T: fmt::Display>(timestamp: T) -> SerdeError<T, u8> {
|
||||||
|
SerdeError::NonExistent::<T, u8> { timestamp }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
impl<V: fmt::Display, D: fmt::Display> fmt::Debug for SerdeError<V, D> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "ChronoSerdeError({})", self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// impl<V: fmt::Display, D: fmt::Debug> core::error::Error for SerdeError<V, D> {}
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
impl<V: fmt::Display, D: fmt::Display> fmt::Display for SerdeError<V, D> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
&SerdeError::NonExistent { ref timestamp } => write!(
|
||||||
|
f, "value is not a legal timestamp: {}", timestamp),
|
||||||
|
&SerdeError::Ambiguous { ref timestamp, ref min, ref max } => write!(
|
||||||
|
f, "value is an ambiguous timestamp: {}, could be either of {}, {}",
|
||||||
|
timestamp, min, max),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The day of week.
|
/// The day of week.
|
||||||
///
|
///
|
||||||
/// The order of the days of week depends on the context.
|
/// The order of the days of week depends on the context.
|
||||||
|
|
|
@ -1642,14 +1642,14 @@ mod serde {
|
||||||
fn visit_str<E>(self, value: &str) -> Result<NaiveDate, E>
|
fn visit_str<E>(self, value: &str) -> Result<NaiveDate, E>
|
||||||
where E: de::Error
|
where E: de::Error
|
||||||
{
|
{
|
||||||
value.parse().map_err(|err| E::custom(format!("{}", err)))
|
value.parse().map_err(E::custom)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature = "std", test)))]
|
#[cfg(not(any(feature = "std", test)))]
|
||||||
fn visit_str<E>(self, value: &str) -> Result<NaiveDate, E>
|
fn visit_str<E>(self, value: &str) -> Result<NaiveDate, E>
|
||||||
where E: de::Error
|
where E: de::Error
|
||||||
{
|
{
|
||||||
value.parse().map_err(|err| E::custom(err))
|
value.parse().map_err(E::custom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1668,8 +1668,6 @@ pub mod rustc_serialize {
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
pub mod serde {
|
pub mod serde {
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
use alloc::format;
|
|
||||||
use super::{NaiveDateTime};
|
use super::{NaiveDateTime};
|
||||||
use serdelib::{ser, de};
|
use serdelib::{ser, de};
|
||||||
|
|
||||||
|
@ -1708,7 +1706,7 @@ pub mod serde {
|
||||||
fn visit_str<E>(self, value: &str) -> Result<NaiveDateTime, E>
|
fn visit_str<E>(self, value: &str) -> Result<NaiveDateTime, E>
|
||||||
where E: de::Error
|
where E: de::Error
|
||||||
{
|
{
|
||||||
value.parse().map_err(|err| E::custom(format!("{}", err)))
|
value.parse().map_err(E::custom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1757,11 +1755,9 @@ pub mod serde {
|
||||||
/// ```
|
/// ```
|
||||||
pub mod ts_nanoseconds {
|
pub mod ts_nanoseconds {
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
#[cfg(not(any(feature = "std", test)))]
|
|
||||||
use alloc::format;
|
|
||||||
use serdelib::{ser, de};
|
use serdelib::{ser, de};
|
||||||
|
|
||||||
use NaiveDateTime;
|
use {NaiveDateTime, ne_timestamp};
|
||||||
|
|
||||||
/// Serialize a UTC datetime into an integer number of nanoseconds since the epoch
|
/// Serialize a UTC datetime into an integer number of nanoseconds since the epoch
|
||||||
///
|
///
|
||||||
|
@ -1854,7 +1850,7 @@ pub mod serde {
|
||||||
{
|
{
|
||||||
NaiveDateTime::from_timestamp_opt(value / 1_000_000_000,
|
NaiveDateTime::from_timestamp_opt(value / 1_000_000_000,
|
||||||
(value % 1_000_000_000) as u32)
|
(value % 1_000_000_000) as u32)
|
||||||
.ok_or_else(|| E::custom(format!("value is not a legal timestamp: {}", value)))
|
.ok_or_else(|| E::custom(ne_timestamp(value)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_u64<E>(self, value: u64) -> Result<NaiveDateTime, E>
|
fn visit_u64<E>(self, value: u64) -> Result<NaiveDateTime, E>
|
||||||
|
@ -1862,7 +1858,7 @@ pub mod serde {
|
||||||
{
|
{
|
||||||
NaiveDateTime::from_timestamp_opt(value as i64 / 1_000_000_000,
|
NaiveDateTime::from_timestamp_opt(value as i64 / 1_000_000_000,
|
||||||
(value as i64 % 1_000_000_000) as u32)
|
(value as i64 % 1_000_000_000) as u32)
|
||||||
.ok_or_else(|| E::custom(format!("value is not a legal timestamp: {}", value)))
|
.ok_or_else(|| E::custom(ne_timestamp(value)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1904,11 +1900,9 @@ pub mod serde {
|
||||||
/// ```
|
/// ```
|
||||||
pub mod ts_milliseconds {
|
pub mod ts_milliseconds {
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
#[cfg(not(any(feature = "std", test)))]
|
|
||||||
use alloc::format;
|
|
||||||
use serdelib::{ser, de};
|
use serdelib::{ser, de};
|
||||||
|
|
||||||
use NaiveDateTime;
|
use {NaiveDateTime, ne_timestamp};
|
||||||
|
|
||||||
/// Serialize a UTC datetime into an integer number of milliseconds since the epoch
|
/// Serialize a UTC datetime into an integer number of milliseconds since the epoch
|
||||||
///
|
///
|
||||||
|
@ -2001,7 +1995,7 @@ pub mod serde {
|
||||||
{
|
{
|
||||||
NaiveDateTime::from_timestamp_opt(value / 1000,
|
NaiveDateTime::from_timestamp_opt(value / 1000,
|
||||||
((value % 1000) * 1_000_000) as u32)
|
((value % 1000) * 1_000_000) as u32)
|
||||||
.ok_or_else(|| E::custom(format!("value is not a legal timestamp: {}", value)))
|
.ok_or_else(|| E::custom(ne_timestamp(value)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_u64<E>(self, value: u64) -> Result<NaiveDateTime, E>
|
fn visit_u64<E>(self, value: u64) -> Result<NaiveDateTime, E>
|
||||||
|
@ -2009,7 +2003,7 @@ pub mod serde {
|
||||||
{
|
{
|
||||||
NaiveDateTime::from_timestamp_opt((value / 1000) as i64,
|
NaiveDateTime::from_timestamp_opt((value / 1000) as i64,
|
||||||
((value % 1000) * 1_000_000) as u32)
|
((value % 1000) * 1_000_000) as u32)
|
||||||
.ok_or_else(|| E::custom(format!("value is not a legal timestamp: {}", value)))
|
.ok_or_else(|| E::custom(ne_timestamp(value)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2051,11 +2045,9 @@ pub mod serde {
|
||||||
/// ```
|
/// ```
|
||||||
pub mod ts_seconds {
|
pub mod ts_seconds {
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
#[cfg(not(any(feature = "std", test)))]
|
|
||||||
use alloc::format;
|
|
||||||
use serdelib::{ser, de};
|
use serdelib::{ser, de};
|
||||||
|
|
||||||
use NaiveDateTime;
|
use {NaiveDateTime, ne_timestamp};
|
||||||
|
|
||||||
/// Serialize a UTC datetime into an integer number of seconds since the epoch
|
/// Serialize a UTC datetime into an integer number of seconds since the epoch
|
||||||
///
|
///
|
||||||
|
@ -2147,14 +2139,14 @@ pub mod serde {
|
||||||
where E: de::Error
|
where E: de::Error
|
||||||
{
|
{
|
||||||
NaiveDateTime::from_timestamp_opt(value, 0)
|
NaiveDateTime::from_timestamp_opt(value, 0)
|
||||||
.ok_or_else(|| E::custom(format!("value is not a legal timestamp: {}", value)))
|
.ok_or_else(|| E::custom(ne_timestamp(value)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_u64<E>(self, value: u64) -> Result<NaiveDateTime, E>
|
fn visit_u64<E>(self, value: u64) -> Result<NaiveDateTime, E>
|
||||||
where E: de::Error
|
where E: de::Error
|
||||||
{
|
{
|
||||||
NaiveDateTime::from_timestamp_opt(value as i64, 0)
|
NaiveDateTime::from_timestamp_opt(value as i64, 0)
|
||||||
.ok_or_else(|| E::custom(format!("value is not a legal timestamp: {}", value)))
|
.ok_or_else(|| E::custom(ne_timestamp(value)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1416,8 +1416,6 @@ mod rustc_serialize {
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
mod serde {
|
mod serde {
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
use alloc::format;
|
|
||||||
use super::NaiveTime;
|
use super::NaiveTime;
|
||||||
use serdelib::{ser, de};
|
use serdelib::{ser, de};
|
||||||
|
|
||||||
|
@ -1445,7 +1443,7 @@ mod serde {
|
||||||
fn visit_str<E>(self, value: &str) -> Result<NaiveTime, E>
|
fn visit_str<E>(self, value: &str) -> Result<NaiveTime, E>
|
||||||
where E: de::Error
|
where E: de::Error
|
||||||
{
|
{
|
||||||
value.parse().map_err(|err| E::custom(format!("{}", err)))
|
value.parse().map_err(E::custom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue