mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-25 13:57:55 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d4d2061a2e | |||
| c202ce13dc | |||
| 1c9478bfa6 | |||
| 1232cfd194 | |||
| 2c49f9aad3 |
@@ -15,10 +15,15 @@ You may be looking for:
|
|||||||
|
|
||||||
## Serde in action
|
## 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
|
```rust
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
extern crate serde;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "0.9.13"
|
version = "0.9.14"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "A generic serialization/deserialization framework"
|
description = "A generic serialization/deserialization framework"
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ use alloc::arc::Arc;
|
|||||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
|
|
||||||
|
use core::cell::{Cell, RefCell};
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
use std::sync::{Mutex, RwLock};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@@ -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:
|
// This is a cleaned-up version of the impl generated by:
|
||||||
|
|||||||
@@ -64,6 +64,10 @@
|
|||||||
//! - Rc\<T\>
|
//! - Rc\<T\>
|
||||||
//! - Arc\<T\>
|
//! - Arc\<T\>
|
||||||
//! - Cow\<'a, T\>
|
//! - Cow\<'a, T\>
|
||||||
|
//! - Cell\<T\>
|
||||||
|
//! - RefCell\<T\>
|
||||||
|
//! - Mutex\<T\>
|
||||||
|
//! - RwLock\<T\>
|
||||||
//! - **Collection types**:
|
//! - **Collection types**:
|
||||||
//! - BTreeMap\<K, V\>
|
//! - BTreeMap\<K, V\>
|
||||||
//! - BTreeSet\<T\>
|
//! - BTreeSet\<T\>
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ use alloc::arc::Arc;
|
|||||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
|
|
||||||
|
use core::cell::{Cell, RefCell};
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
use std::sync::{Mutex, RwLock};
|
||||||
|
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
#[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>
|
impl<T, E> Serialize for Result<T, E>
|
||||||
|
|||||||
@@ -61,6 +61,10 @@
|
|||||||
//! - Rc\<T\>
|
//! - Rc\<T\>
|
||||||
//! - Arc\<T\>
|
//! - Arc\<T\>
|
||||||
//! - Cow\<'a, T\>
|
//! - Cow\<'a, T\>
|
||||||
|
//! - Cell\<T\>
|
||||||
|
//! - RefCell\<T\>
|
||||||
|
//! - Mutex\<T\>
|
||||||
|
//! - RwLock\<T\>
|
||||||
//! - **Collection types**:
|
//! - **Collection types**:
|
||||||
//! - BTreeMap\<K, V\>
|
//! - BTreeMap\<K, V\>
|
||||||
//! - BTreeSet\<T\>
|
//! - BTreeSet\<T\>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "0.9.13"
|
version = "0.9.14"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "0.9.13"
|
version = "0.9.14"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Token De/Serializer for testing De/Serialize implementations"
|
description = "Token De/Serializer for testing De/Serialize implementations"
|
||||||
|
|||||||
Reference in New Issue
Block a user