Compare commits

...

15 Commits

Author SHA1 Message Date
David Tolnay d690ffda8d Release 0.8.4 2016-08-22 11:37:53 -04:00
David Tolnay 18a775277f Merge pull request #514 from nox/maps
Introduce MapDeserializer::unbounded (fixes #512)
2016-08-22 09:05:50 -04:00
Anthony Ramine fbb250766d Introduce MapDeserializer::unbounded (fixes #512) 2016-08-22 09:11:10 +02:00
David Tolnay 71116b860a Merge pull request #513 from nox/cow
Implement ValueDeserializer for Cow<str>
2016-08-21 14:07:56 -04:00
Anthony Ramine ce3f134145 Implement ValueDeserializer for Cow<str> 2016-08-21 19:52:13 +02:00
David Tolnay 80507d650c Merge pull request #511 from serde-rs/extra
Switch to syntex::with_extra_stack
2016-08-19 21:27:17 -04:00
David Tolnay 0ae61a3dd1 Switch to syntex::with_extra_stack 2016-08-19 21:09:55 -04:00
David Tolnay 5fb73073bd Release 0.8.3 2016-08-19 13:11:59 -04:00
David Tolnay 63d484d50c Merge pull request #510 from serde-rs/clippy
Re-enable clippy
2016-08-19 13:01:24 -04:00
David Tolnay f3f29f81bc Fix new lints 2016-08-19 12:46:45 -04:00
David Tolnay 621588b258 Revert "Disable clippy until Manishearth/rust-clippy#1174 is fixed"
This reverts commit 2bc1d62e50.
2016-08-19 11:47:31 -04:00
Homu 7aba920dec Auto merge of #509 - serde-rs:cow, r=oli-obk
Fix codegen with lifetimes but no type parameters

Fixes #507.
2016-08-20 00:16:54 +09:00
David Tolnay a732b9bad3 Fix codegen with lifetimes but no type parameters 2016-08-19 11:12:38 -04:00
Oliver Schneider 6723da67b3 Merge pull request #506 from serde-rs/https
HTTPS for serde.rs
2016-08-19 10:57:52 +02:00
David Tolnay 2d99a50c27 HTTPS for serde.rs 2016-08-18 17:08:05 -04:00
15 changed files with 190 additions and 97 deletions
+5 -5
View File
@@ -6,11 +6,11 @@
You may be looking for:
- [An overview of Serde](http://serde.rs/)
- [Data formats supported by Serde](http://serde.rs/#data-formats)
- [Setting up `#[derive(Serialize, Deserialize)]`](http://serde.rs/codegen.html)
- [Examples](http://serde.rs/examples.html)
- [API documentation](http://docs.serde.rs/serde/)
- [An overview of Serde](https://serde.rs/)
- [Data formats supported by Serde](https://serde.rs/#data-formats)
- [Setting up `#[derive(Serialize, Deserialize)]`](https://serde.rs/codegen.html)
- [Examples](https://serde.rs/examples.html)
- [API documentation](https://docs.serde.rs/serde/)
## Serde in action
+4 -3
View File
@@ -1,11 +1,12 @@
[package]
name = "serde"
version = "0.8.2"
version = "0.8.4"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "A generic serialization/deserialization framework"
homepage = "https://serde.rs"
repository = "https://github.com/serde-rs/serde"
documentation = "http://docs.serde.rs/serde/"
documentation = "https://docs.serde.rs/serde/"
readme = "../README.md"
keywords = ["serde", "serialization"]
include = ["Cargo.toml", "src/**/*.rs"]
@@ -17,7 +18,7 @@ std = []
unstable = []
alloc = ["unstable"]
collections = ["alloc"]
unstable-testing = ["unstable", "std"]
unstable-testing = ["clippy", "unstable", "std"]
[dependencies]
clippy = { version = "^0.*", optional = true }
+127 -10
View File
@@ -12,6 +12,8 @@ use std::collections::{
hash_set,
};
#[cfg(feature = "std")]
use std::borrow::Cow;
#[cfg(feature = "std")]
use std::vec;
#[cfg(all(feature = "collections", not(feature = "std")))]
@@ -24,6 +26,8 @@ use collections::{
btree_set,
vec,
};
#[cfg(all(feature = "collections", not(feature = "std")))]
use collections::borrow::Cow;
#[cfg(all(feature = "unstable", feature = "collections"))]
use collections::borrow::ToOwned;
@@ -128,7 +132,7 @@ impl fmt::Display for Error {
write!(formatter, "Unknown variant: {}", variant)
}
Error::UnknownField(ref field) => write!(formatter, "Unknown field: {}", field),
Error::MissingField(ref field) => write!(formatter, "Missing field: {}", field),
Error::MissingField(field) => write!(formatter, "Missing field: {}", field),
}
}
}
@@ -463,6 +467,105 @@ impl<'a, E> de::VariantVisitor for StringDeserializer<E>
///////////////////////////////////////////////////////////////////////////////
/// A helper deserializer that deserializes a `String`.
#[cfg(any(feature = "std", feature = "collections"))]
pub struct CowStrDeserializer<'a, E>(Option<Cow<'a, str>>, PhantomData<E>);
#[cfg(any(feature = "std", feature = "collections"))]
impl<'a, E> ValueDeserializer<E> for Cow<'a, str>
where E: de::Error,
{
type Deserializer = CowStrDeserializer<'a, E>;
fn into_deserializer(self) -> CowStrDeserializer<'a, E> {
CowStrDeserializer(Some(self), PhantomData)
}
}
#[cfg(any(feature = "std", feature = "collections"))]
impl<'a, E> de::Deserializer for CowStrDeserializer<'a, E>
where E: de::Error,
{
type Error = E;
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
where V: de::Visitor,
{
match self.0.take() {
Some(Cow::Borrowed(string)) => visitor.visit_str(string),
Some(Cow::Owned(string)) => visitor.visit_string(string),
None => Err(de::Error::end_of_stream()),
}
}
fn deserialize_enum<V>(&mut self,
_name: &str,
_variants: &'static [&'static str],
mut visitor: V) -> Result<V::Value, Self::Error>
where V: de::EnumVisitor,
{
visitor.visit(self)
}
de_forward_to_deserialize!{
deserialize_bool,
deserialize_f64, deserialize_f32,
deserialize_u8, deserialize_u16, deserialize_u32, deserialize_u64, deserialize_usize,
deserialize_i8, deserialize_i16, deserialize_i32, deserialize_i64, deserialize_isize,
deserialize_char, deserialize_str, deserialize_string,
deserialize_ignored_any,
deserialize_bytes,
deserialize_unit_struct, deserialize_unit,
deserialize_seq, deserialize_seq_fixed_size,
deserialize_map, deserialize_newtype_struct, deserialize_struct_field,
deserialize_tuple,
deserialize_struct, deserialize_tuple_struct,
deserialize_option
}
}
#[cfg(any(feature = "std", feature = "collections"))]
impl<'a, E> de::VariantVisitor for CowStrDeserializer<'a, E>
where E: de::Error,
{
type Error = E;
fn visit_variant<T>(&mut self) -> Result<T, Self::Error>
where T: de::Deserialize,
{
de::Deserialize::deserialize(self)
}
fn visit_unit(&mut self) -> Result<(), Self::Error> {
Ok(())
}
fn visit_newtype<T>(&mut self) -> Result<T, Self::Error>
where T: super::Deserialize,
{
let (value,) = try!(self.visit_tuple(1, super::impls::TupleVisitor1::new()));
Ok(value)
}
fn visit_tuple<V>(&mut self,
_len: usize,
_visitor: V) -> Result<V::Value, Self::Error>
where V: super::Visitor
{
Err(super::Error::invalid_type(super::Type::TupleVariant))
}
fn visit_struct<V>(&mut self,
_fields: &'static [&'static str],
_visitor: V) -> Result<V::Value, Self::Error>
where V: super::Visitor
{
Err(super::Error::invalid_type(super::Type::StructVariant))
}
}
///////////////////////////////////////////////////////////////////////////////
/// A helper deserializer that deserializes a sequence.
pub struct SeqDeserializer<I, E> {
iter: I,
@@ -648,7 +751,7 @@ pub struct MapDeserializer<I, K, V, E>
{
iter: I,
value: Option<V>,
len: usize,
len: Option<usize>,
marker: PhantomData<E>,
}
@@ -658,12 +761,23 @@ impl<I, K, V, E> MapDeserializer<I, K, V, E>
V: ValueDeserializer<E>,
E: de::Error,
{
/// Construct a new `MapDeserializer<I, K, V>`.
/// Construct a new `MapDeserializer<I, K, V, E>` with a specific length.
pub fn new(iter: I, len: usize) -> Self {
MapDeserializer {
iter: iter,
value: None,
len: len,
len: Some(len),
marker: PhantomData,
}
}
/// Construct a new `MapDeserializer<I, K, V, E>` that is not bounded
/// by a specific length and that delegates to `iter` for its size hint.
pub fn unbounded(iter: I) -> Self {
MapDeserializer {
iter: iter,
value: None,
len: None,
marker: PhantomData,
}
}
@@ -714,7 +828,9 @@ impl<I, K, V, E> de::MapVisitor for MapDeserializer<I, K, V, E>
{
match self.iter.next() {
Some((key, value)) => {
self.len -= 1;
if let Some(len) = self.len.as_mut() {
*len -= 1;
}
self.value = Some(value);
let mut de = key.into_deserializer();
Ok(Some(try!(de::Deserialize::deserialize(&mut de))))
@@ -738,15 +854,16 @@ impl<I, K, V, E> de::MapVisitor for MapDeserializer<I, K, V, E>
}
fn end(&mut self) -> Result<(), Self::Error> {
if self.len == 0 {
Ok(())
} else {
Err(de::Error::invalid_length(self.len))
match self.len {
Some(len) if len > 0 => Err(de::Error::invalid_length(len)),
_ => Ok(())
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
(self.len, Some(self.len))
self.len.map_or_else(
|| self.iter.size_hint(),
|len| (len, Some(len)))
}
}
+1 -1
View File
@@ -9,7 +9,7 @@
//! For a detailed tutorial on the different ways to use serde please check out the
//! [github repository](https://github.com/serde-rs/serde)
#![doc(html_root_url="http://docs.serde.rs")]
#![doc(html_root_url="https://docs.serde.rs")]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "unstable", feature(reflect_marker, unicode, nonzero, plugin, step_trait, zero_one))]
#![cfg_attr(feature = "alloc", feature(alloc))]
+12 -11
View File
@@ -1,11 +1,12 @@
[package]
name = "serde_codegen"
version = "0.8.2"
version = "0.8.4"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "Macros to auto-generate implementations for the serde framework"
homepage = "https://serde.rs"
repository = "https://github.com/serde-rs/serde"
documentation = "https://github.com/serde-rs/serde"
documentation = "https://serde.rs/codegen.html"
keywords = ["serde", "serialization"]
build = "build.rs"
include = ["Cargo.toml", "build.rs", "src/**/*.rs", "src/lib.rs.in"]
@@ -13,7 +14,7 @@ include = ["Cargo.toml", "build.rs", "src/**/*.rs", "src/lib.rs.in"]
[features]
default = ["with-syntex"]
unstable = ["quasi_macros"]
unstable-testing = []
unstable-testing = ["clippy"]
with-syntex = [
"quasi/with-syntex",
"quasi_codegen",
@@ -24,14 +25,14 @@ with-syntex = [
]
[build-dependencies]
quasi_codegen = { version = "^0.17.0", optional = true }
syntex = { version = "^0.41.0", optional = true }
quasi_codegen = { version = "^0.18.0", optional = true }
syntex = { version = "^0.42.2", optional = true }
[dependencies]
aster = { version = "^0.24.0", default-features = false }
aster = { version = "^0.25.0", default-features = false }
clippy = { version = "^0.*", optional = true }
quasi = { version = "^0.17.0", default-features = false }
quasi_macros = { version = "^0.17.0", optional = true }
serde_codegen_internals = { version = "=0.6.0", default-features = false, path = "../serde_codegen_internals" }
syntex = { version = "^0.41.0", optional = true }
syntex_syntax = { version = "^0.41.0", optional = true }
quasi = { version = "^0.18.0", default-features = false }
quasi_macros = { version = "^0.18.0", optional = true }
serde_codegen_internals = { version = "=0.7.0", default-features = false, path = "../serde_codegen_internals" }
syntex = { version = "^0.42.2", optional = true }
syntex_syntax = { version = "^0.42.0", optional = true }
+1 -1
View File
@@ -192,7 +192,7 @@ fn deserialize_visitor(
builder: &aster::AstBuilder,
generics: &ast::Generics,
) -> (P<ast::Item>, P<ast::Ty>, P<ast::Expr>) {
if generics.ty_params.is_empty() {
if generics.lifetimes.is_empty() && generics.ty_params.is_empty() {
(
builder.item().unit_struct("__Visitor"),
builder.ty().id("__Visitor"),
-36
View File
@@ -1,36 +0,0 @@
use std::env;
use std::ffi::OsStr;
use std::ops::Drop;
pub fn set_if_unset<K, V>(k: K, v: V) -> TmpEnv<K>
where K: AsRef<OsStr>,
V: AsRef<OsStr>,
{
match env::var(&k) {
Ok(_) => TmpEnv::WasAlreadySet,
Err(_) => {
env::set_var(&k, v);
TmpEnv::WasNotSet { k: k }
}
}
}
#[must_use]
pub enum TmpEnv<K>
where K: AsRef<OsStr>,
{
WasAlreadySet,
WasNotSet {
k: K,
}
}
impl<K> Drop for TmpEnv<K>
where K: AsRef<OsStr>,
{
fn drop(&mut self) {
if let TmpEnv::WasNotSet { ref k } = *self {
env::remove_var(k);
}
}
}
+1 -8
View File
@@ -35,9 +35,6 @@ include!(concat!(env!("OUT_DIR"), "/lib.rs"));
#[cfg(not(feature = "with-syntex"))]
include!("lib.rs.in");
#[cfg(feature = "with-syntex")]
mod env;
#[cfg(feature = "with-syntex")]
pub fn expand<S, D>(src: S, dst: D) -> Result<(), syntex::Error>
where S: AsRef<Path>,
@@ -86,11 +83,7 @@ pub fn expand<S, D>(src: S, dst: D) -> Result<(), syntex::Error>
reg.expand("", src, dst)
};
// 16 MB stack unless otherwise specified
let _tmp_env = env::set_if_unset("RUST_MIN_STACK", "16777216");
use std::thread;
thread::spawn(expand_thread).join().unwrap()
syntex::with_extra_stack(expand_thread)
}
#[cfg(not(feature = "with-syntex"))]
+6 -5
View File
@@ -1,20 +1,21 @@
[package]
name = "serde_codegen_internals"
version = "0.6.0"
version = "0.7.0"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "AST representation used by Serde codegen. Unstable."
homepage = "https://serde.rs"
repository = "https://github.com/serde-rs/serde"
documentation = "https://github.com/serde-rs/serde"
documentation = "https://docs.serde.rs/serde_codegen_internals/"
keywords = ["serde", "serialization"]
include = ["Cargo.toml", "src/**/*.rs"]
[features]
default = ["with-syntex"]
unstable-testing = []
unstable-testing = ["clippy"]
with-syntex = ["syntex_syntax", "syntex_errors"]
[dependencies]
clippy = { version = "^0.*", optional = true }
syntex_syntax = { version = "^0.41.0", optional = true }
syntex_errors = { version = "^0.41.0", optional = true }
syntex_syntax = { version = "^0.42.0", optional = true }
syntex_errors = { version = "^0.42.0", optional = true }
+7 -5
View File
@@ -449,12 +449,14 @@ impl Field {
}
}
type SerAndDe<T> = (Option<Spanned<T>>, Option<Spanned<T>>);
fn get_ser_and_de<T, F>(
cx: &ExtCtxt,
attribute: &'static str,
items: &[P<ast::MetaItem>],
f: F
) -> Result<(Option<Spanned<T>>, Option<Spanned<T>>), ()>
) -> Result<SerAndDe<T>, ()>
where F: Fn(&ExtCtxt, &str, &ast::Lit) -> Result<T, ()>,
{
let mut ser_item = Attr::none(cx, attribute);
@@ -492,21 +494,21 @@ fn get_ser_and_de<T, F>(
fn get_renames(
cx: &ExtCtxt,
items: &[P<ast::MetaItem>],
) -> Result<(Option<Spanned<InternedString>>, Option<Spanned<InternedString>>), ()> {
) -> Result<SerAndDe<InternedString>, ()> {
get_ser_and_de(cx, "rename", items, get_str_from_lit)
}
fn get_where_predicates(
cx: &ExtCtxt,
items: &[P<ast::MetaItem>],
) -> Result<(Option<Spanned<Vec<ast::WherePredicate>>>, Option<Spanned<Vec<ast::WherePredicate>>>), ()> {
) -> Result<SerAndDe<Vec<ast::WherePredicate>>, ()> {
get_ser_and_de(cx, "bound", items, parse_lit_into_where)
}
pub fn get_serde_meta_items(attr: &ast::Attribute) -> Option<&[P<ast::MetaItem>]> {
match attr.node.value.node {
ast::MetaItemKind::List(ref name, ref items) if name == &"serde" => {
attr::mark_used(&attr);
attr::mark_used(attr);
Some(items)
}
_ => None
@@ -570,7 +572,7 @@ fn get_str_from_lit(cx: &ExtCtxt, name: &str, lit: &ast::Lit) -> Result<Interned
name,
lit_to_string(lit)));
return Err(());
Err(())
}
}
}
+7 -5
View File
@@ -1,11 +1,12 @@
[package]
name = "serde_macros"
version = "0.8.2"
version = "0.8.4"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "Macros to auto-generate implementations for the serde framework"
homepage = "https://serde.rs"
repository = "https://github.com/serde-rs/serde"
documentation = "https://github.com/serde-rs/serde"
documentation = "https://serde.rs/codegen.html"
keywords = ["serde", "serialization"]
include = ["Cargo.toml", "src/**/*.rs", "build.rs"]
build = "build.rs"
@@ -16,6 +17,7 @@ plugin = true
[features]
unstable-testing = [
"clippy",
"skeptic",
"serde_json",
"serde/unstable-testing",
@@ -27,7 +29,7 @@ skeptic = { version = "^0.6.0", optional = true }
[dependencies]
clippy = { version = "^0.*", optional = true }
serde_codegen = { version = "=0.8.2", default-features = false, features = ["unstable"], path = "../serde_codegen" }
serde_codegen = { version = "=0.8.4", default-features = false, features = ["unstable"], path = "../serde_codegen" }
skeptic = { version = "^0.6.0", optional = true }
serde_json = { version = "0.8.0", optional = true }
@@ -35,8 +37,8 @@ serde_json = { version = "0.8.0", optional = true }
compiletest_rs = "^0.2.0"
fnv = "1.0"
rustc-serialize = "^0.3.16"
serde = { version = "0.8.2", path = "../serde" }
serde_test = { version = "0.8.2", path = "../serde_test" }
serde = { version = "0.8.4", path = "../serde" }
serde_test = { version = "0.8.4", path = "../serde_test" }
[[test]]
name = "test"
+1 -1
View File
@@ -1,5 +1,5 @@
#![feature(custom_derive, plugin)]
#![plugin(serde_macros)]
#![plugin(serde_macros, clippy)]
#![deny(identity_op)]
+4 -3
View File
@@ -1,14 +1,15 @@
[package]
name = "serde_test"
version = "0.8.2"
version = "0.8.4"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "Token De/Serializer for testing De/Serialize implementations"
homepage = "https://serde.rs"
repository = "https://github.com/serde-rs/serde"
documentation = "http://docs.serde.rs/serde/"
documentation = "https://docs.serde.rs/serde_test/"
readme = "../README.md"
keywords = ["serde", "serialization"]
include = ["Cargo.toml", "src/**/*.rs"]
[dependencies]
serde = { version = "0.8.2", path = "../serde" }
serde = { version = "0.8.4", path = "../serde" }
+4 -3
View File
@@ -1,17 +1,18 @@
[package]
name = "serde_testing"
version = "0.8.2"
version = "0.8.4"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "A generic serialization/deserialization framework"
homepage = "https://serde.rs"
repository = "https://github.com/serde-rs/serde"
documentation = "http://docs.serde.rs/serde/"
documentation = "https://docs.serde.rs/serde/"
readme = "README.md"
keywords = ["serialization"]
build = "build.rs"
[features]
unstable-testing = ["serde/unstable-testing", "serde_codegen/unstable-testing"]
unstable-testing = ["clippy", "serde/unstable-testing", "serde_codegen/unstable-testing"]
[build-dependencies]
serde_codegen = { path = "../serde_codegen", features = ["with-syntex"] }
+10
View File
@@ -6,6 +6,7 @@ extern crate serde;
use self::serde::ser::{Serialize, Serializer};
use self::serde::de::{Deserialize, Deserializer};
use std::borrow::Cow;
use std::marker::PhantomData;
//////////////////////////////////////////////////////////////////////////
@@ -177,6 +178,15 @@ fn test_gen() {
e: E,
}
assert::<WithTraits2<X, X>>();
#[derive(Serialize, Deserialize)]
struct CowStr<'a>(Cow<'a, str>);
assert::<CowStr>();
#[derive(Serialize, Deserialize)]
#[serde(bound(deserialize = "T::Owned: Deserialize"))]
struct CowT<'a, T: ?Sized + 'a + ToOwned>(Cow<'a, T>);
assert::<CowT<str>>();
}
//////////////////////////////////////////////////////////////////////////