Compare commits

...

8 Commits

Author SHA1 Message Date
David Tolnay ae79451b7a Release 0.9.15 2017-04-23 16:37:43 -07:00
David Tolnay 1a2b3815ef Merge pull request #899 from SimonSapin/z-is-dead-in-0.9-too
Remove usage of unstable core::num::Zero, which was removed upstream.
2017-04-23 16:34:06 -07:00
Simon Sapin 1d6ecf3c2c Remove usage of unstable core::num::Zero, which was removed upstream.
https://github.com/rust-lang/rust/pull/41437

Backport of https://github.com/serde-rs/serde/pull/898 to 0.9.x
2017-04-24 08:25:08 +09:00
David Tolnay d4d2061a2e Release 0.9.14 2017-04-17 07:33:45 -07:00
David Tolnay c202ce13dc Merge pull request #882 from jethrogb/feature/interior_mut_types
Add Serialize/Deserialize for std types that provide interior mutability
2017-04-17 07:32:13 -07:00
Jethro Beekman 1c9478bfa6 Add Serialize/Deserialize for std types that provide interior mutability
Fixes #179
2017-04-16 22:59:17 -07:00
David Tolnay 1232cfd194 Add playground link to readme 2017-04-13 10:19:22 -07:00
David Tolnay 2c49f9aad3 Recommend 'extern crate serde' 2017-04-08 13:53:13 -07:00
9 changed files with 132 additions and 14 deletions
+5
View File
@@ -15,10 +15,15 @@ You may be looking for:
## Serde in action
<a href="http://play.integer32.com/?gist=9003c5b88c1f4989941925d7190c6eec" target="_blank">
<img align="right" width="50" src="https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/img/run.png">
</a>
```rust
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
#[derive(Serialize, Deserialize, Debug)]
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "serde"
version = "0.9.13"
version = "0.9.15"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "A generic serialization/deserialization framework"
+58 -10
View File
@@ -20,10 +20,14 @@ use core::fmt;
#[cfg(feature = "std")]
use core::hash::{Hash, BuildHasher};
use core::marker::PhantomData;
#[cfg(all(feature="unstable"))]
use core::mem;
#[cfg(feature = "std")]
use std::net;
#[cfg(feature = "std")]
use std::path;
#[cfg(all(feature="unstable"))]
use core::slice;
use core::str;
#[cfg(feature = "std")]
use std::ffi::{CString, OsString};
@@ -43,6 +47,11 @@ use alloc::arc::Arc;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::boxed::Box;
use core::cell::{Cell, RefCell};
#[cfg(feature = "std")]
use std::sync::{Mutex, RwLock};
#[cfg(feature = "std")]
use std::time::Duration;
@@ -52,10 +61,6 @@ use std;
#[cfg(feature = "unstable")]
use core::nonzero::{NonZero, Zeroable};
#[cfg(feature = "unstable")]
#[allow(deprecated)] // required for impl Deserialize for NonZero<T>
use core::num::Zero;
use de::{Deserialize, Deserializer, EnumVisitor, Error, MapVisitor, SeqVisitor, Unexpected,
VariantVisitor, Visitor};
use de::from_primitive::FromPrimitive;
@@ -1106,6 +1111,44 @@ impl<'a, T: ?Sized> Deserialize for Cow<'a, T>
}
}
impl<T: Deserialize + Copy> Deserialize for Cell<T> {
fn deserialize<D>(deserializer: D) -> Result<Cell<T>, D::Error>
where D: Deserializer
{
let val = try!(Deserialize::deserialize(deserializer));
Ok(Cell::new(val))
}
}
impl<T: Deserialize> Deserialize for RefCell<T> {
fn deserialize<D>(deserializer: D) -> Result<RefCell<T>, D::Error>
where D: Deserializer
{
let val = try!(Deserialize::deserialize(deserializer));
Ok(RefCell::new(val))
}
}
#[cfg(feature = "std")]
impl<T: Deserialize> Deserialize for Mutex<T> {
fn deserialize<D>(deserializer: D) -> Result<Mutex<T>, D::Error>
where D: Deserializer
{
let val = try!(Deserialize::deserialize(deserializer));
Ok(Mutex::new(val))
}
}
#[cfg(feature = "std")]
impl<T: Deserialize> Deserialize for RwLock<T> {
fn deserialize<D>(deserializer: D) -> Result<RwLock<T>, D::Error>
where D: Deserializer
{
let val = try!(Deserialize::deserialize(deserializer));
Ok(RwLock::new(val))
}
}
///////////////////////////////////////////////////////////////////////////////
// This is a cleaned-up version of the impl generated by:
@@ -1366,18 +1409,23 @@ impl<Idx: Deserialize> Deserialize for std::ops::Range<Idx> {
///////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "unstable")]
#[allow(deprecated)] // num::Zero is deprecated but there is no replacement
impl<T> Deserialize for NonZero<T>
where T: Deserialize + PartialEq + Zeroable + Zero
where T: Deserialize + Zeroable
{
fn deserialize<D>(deserializer: D) -> Result<NonZero<T>, D::Error>
where D: Deserializer
{
let value = try!(Deserialize::deserialize(deserializer));
if value == Zero::zero() {
return Err(Error::custom("expected a non-zero value"));
}
unsafe { Ok(NonZero::new(value)) }
unsafe {
let ptr = &value as *const T as *const u8;
if slice::from_raw_parts(ptr, mem::size_of::<T>()).iter().all(|&b| b == 0) {
return Err(Error::custom("expected a non-zero value"));
}
// Waiting for a safe way to construct NonZero<T>:
// https://github.com/rust-lang/rust/issues/27730#issuecomment-269726075
Ok(NonZero::new(value))
}
}
}
+4
View File
@@ -64,6 +64,10 @@
//! - Rc\<T\>
//! - Arc\<T\>
//! - Cow\<'a, T\>
//! - Cell\<T\>
//! - RefCell\<T\>
//! - Mutex\<T\>
//! - RwLock\<T\>
//! - **Collection types**:
//! - BTreeMap\<K, V\>
//! - BTreeSet\<T\>
+1 -1
View File
@@ -61,7 +61,7 @@
#![doc(html_root_url="https://docs.serde.rs")]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "unstable", feature(nonzero, specialization, zero_one, into_boxed_c_str))]
#![cfg_attr(feature = "unstable", feature(nonzero, specialization, into_boxed_c_str))]
#![cfg_attr(feature = "alloc", feature(alloc))]
#![cfg_attr(feature = "collections", feature(collections))]
#![cfg_attr(feature = "cargo-clippy", allow(linkedlist, type_complexity, doc_markdown))]
+57
View File
@@ -36,6 +36,11 @@ use alloc::arc::Arc;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::boxed::Box;
use core::cell::{Cell, RefCell};
#[cfg(feature = "std")]
use std::sync::{Mutex, RwLock};
use core::marker::PhantomData;
#[cfg(feature = "unstable")]
@@ -586,6 +591,58 @@ impl<'a, T: ?Sized> Serialize for Cow<'a, T>
}
}
impl<T> Serialize for Cell<T>
where T: Serialize + Copy
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer
{
self.get().serialize(serializer)
}
}
impl<T> Serialize for RefCell<T>
where T: Serialize
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer
{
self.borrow().serialize(serializer)
}
}
#[cfg(feature = "std")]
impl<T> Serialize for Mutex<T>
where T: Serialize
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer
{
match self.lock() {
Ok(locked) => locked.serialize(serializer),
Err(_) => Err(S::Error::custom("lock poison error while serializing")),
}
}
}
#[cfg(feature = "std")]
impl<T> Serialize for RwLock<T>
where T: Serialize
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer
{
match self.read() {
Ok(locked) => locked.serialize(serializer),
Err(_) => Err(S::Error::custom("lock poison error while serializing")),
}
}
}
///////////////////////////////////////////////////////////////////////////////
impl<T, E> Serialize for Result<T, E>
+4
View File
@@ -61,6 +61,10 @@
//! - Rc\<T\>
//! - Arc\<T\>
//! - Cow\<'a, T\>
//! - Cell\<T\>
//! - RefCell\<T\>
//! - Mutex\<T\>
//! - RwLock\<T\>
//! - **Collection types**:
//! - BTreeMap\<K, V\>
//! - BTreeSet\<T\>
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "serde_derive"
version = "0.9.13"
version = "0.9.15"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "serde_test"
version = "0.9.13"
version = "0.9.15"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "Token De/Serializer for testing De/Serialize implementations"