Support Duration in no-std mode on new compilers
This commit is contained in:
parent
94853752a1
commit
b6c4cfec37
@ -24,6 +24,12 @@ fn main() {
|
|||||||
println!("cargo:rustc-cfg=de_rc_dst");
|
println!("cargo:rustc-cfg=de_rc_dst");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Duration available in core since Rust 1.25:
|
||||||
|
// https://blog.rust-lang.org/2018/03/29/Rust-1.25.html#library-stabilizations
|
||||||
|
if minor >= 25 {
|
||||||
|
println!("cargo:rustc-cfg=core_duration");
|
||||||
|
}
|
||||||
|
|
||||||
// 128-bit integers stabilized in Rust 1.26:
|
// 128-bit integers stabilized in Rust 1.26:
|
||||||
// https://blog.rust-lang.org/2018/05/10/Rust-1.26.html
|
// https://blog.rust-lang.org/2018/05/10/Rust-1.26.html
|
||||||
if minor >= 26 {
|
if minor >= 26 {
|
||||||
|
@ -12,7 +12,7 @@ use de::{
|
|||||||
Deserialize, Deserializer, EnumAccess, Error, SeqAccess, Unexpected, VariantAccess, Visitor,
|
Deserialize, Deserializer, EnumAccess, Error, SeqAccess, Unexpected, VariantAccess, Visitor,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(core_duration, feature = "std", feature = "alloc"))]
|
||||||
use de::MapAccess;
|
use de::MapAccess;
|
||||||
|
|
||||||
use de::from_primitive::FromPrimitive;
|
use de::from_primitive::FromPrimitive;
|
||||||
@ -1694,7 +1694,7 @@ forwarded_impl!((T), RwLock<T>, RwLock::new);
|
|||||||
// secs: u64,
|
// secs: u64,
|
||||||
// nanos: u32,
|
// nanos: u32,
|
||||||
// }
|
// }
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(core_duration, feature = "std"))]
|
||||||
impl<'de> Deserialize<'de> for Duration {
|
impl<'de> Deserialize<'de> for Duration {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
@ -1742,7 +1742,7 @@ impl<'de> Deserialize<'de> for Duration {
|
|||||||
b"secs" => Ok(Field::Secs),
|
b"secs" => Ok(Field::Secs),
|
||||||
b"nanos" => Ok(Field::Nanos),
|
b"nanos" => Ok(Field::Nanos),
|
||||||
_ => {
|
_ => {
|
||||||
let value = String::from_utf8_lossy(value);
|
let value = ::export::from_utf8_lossy(value);
|
||||||
Err(Error::unknown_field(&value, FIELDS))
|
Err(Error::unknown_field(&value, FIELDS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,10 @@ mod lib {
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::sync::{Mutex, RwLock};
|
pub use std::sync::{Mutex, RwLock};
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
pub use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
#[cfg(any(core_duration, feature = "std"))]
|
||||||
|
pub use self::core::time::Duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -527,7 +527,7 @@ where
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(core_duration, feature = "std"))]
|
||||||
impl Serialize for Duration {
|
impl Serialize for Duration {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
|
Loading…
x
Reference in New Issue
Block a user