mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-19 09:51:05 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f331cc257 | |||
| ef16c815f6 | |||
| c45a809d5c | |||
| f7d06cae4c | |||
| 31fe82a215 | |||
| ef6ed1d1be | |||
| 9d1251548b | |||
| c20730ee39 | |||
| afd51ef0f4 | |||
| 3167f98689 | |||
| 078b171c1b | |||
| da8d6f678e | |||
| 548eb8f667 | |||
| 1fe39043ee | |||
| c2114491ca | |||
| 9f47c47cad | |||
| d6b39fd2c1 | |||
| 4d6d0ae539 | |||
| dda070f45c |
@@ -109,6 +109,14 @@ jobs:
|
|||||||
- run: cd serde && cargo build --no-default-features
|
- run: cd serde && cargo build --no-default-features
|
||||||
- run: cd serde && cargo build
|
- run: cd serde && cargo build
|
||||||
|
|
||||||
|
derive:
|
||||||
|
name: Rust 1.31.0
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: dtolnay/rust-toolchain@1.31.0
|
||||||
|
- run: cd serde_derive && cargo check
|
||||||
|
|
||||||
alloc:
|
alloc:
|
||||||
name: Rust 1.36.0
|
name: Rust 1.36.0
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
@@ -4,11 +4,6 @@ Serde welcomes contribution from everyone in the form of suggestions, bug
|
|||||||
reports, pull requests, and feedback. This document gives some guidance if you
|
reports, pull requests, and feedback. This document gives some guidance if you
|
||||||
are thinking of helping us.
|
are thinking of helping us.
|
||||||
|
|
||||||
Please reach out here in a GitHub issue or in the #serde IRC channel on
|
|
||||||
[`irc.mozilla.org`] if we can do anything to help you contribute.
|
|
||||||
|
|
||||||
[`irc.mozilla.org`]: https://wiki.mozilla.org/IRC
|
|
||||||
|
|
||||||
## Submitting bug reports and feature requests
|
## Submitting bug reports and feature requests
|
||||||
|
|
||||||
Serde development is spread across lots of repositories, but this serde-rs/serde
|
Serde development is spread across lots of repositories, but this serde-rs/serde
|
||||||
|
|||||||
@@ -75,13 +75,23 @@ fn main() {
|
|||||||
|
|
||||||
## Getting help
|
## Getting help
|
||||||
|
|
||||||
Serde developers live in the #serde channel on [`irc.mozilla.org`][irc]. The
|
Serde is one of the most widely used Rust libraries so any place that Rustaceans
|
||||||
\#rust channel is also a good resource with generally faster response time but
|
congregate will be able to help you out. For chat, consider trying the
|
||||||
less specific knowledge about Serde. If IRC is not your thing or you don't get a
|
[#general] or [#beginners] channels of the unofficial community Discord, the
|
||||||
good response, we are happy to respond to [GitHub issues][issues] as well.
|
[#rust-usage] channel of the official Rust Project Discord, or the
|
||||||
|
[#general][zulip] stream in Zulip. For asynchronous, consider the [\[rust\] tag
|
||||||
|
on StackOverflow][stackoverflow], the [/r/rust] subreddit which has a pinned
|
||||||
|
weekly easy questions post, or the Rust [Discourse forum][discourse]. It's
|
||||||
|
acceptable to file a support issue in this repo but they tend not to get as many
|
||||||
|
eyes as any of the above and may get closed without a response after some time.
|
||||||
|
|
||||||
[irc]: https://wiki.mozilla.org/IRC
|
[#general]: https://discord.com/channels/273534239310479360/274215136414400513
|
||||||
[issues]: https://github.com/serde-rs/serde/issues/new/choose
|
[#beginners]: https://discord.com/channels/273534239310479360/273541522815713281
|
||||||
|
[#rust-usage]: https://discord.com/channels/442252698964721669/443150878111694848
|
||||||
|
[zulip]: https://rust-lang.zulipchat.com/#narrow/stream/122651-general
|
||||||
|
[stackoverflow]: https://stackoverflow.com/questions/tagged/rust
|
||||||
|
[/r/rust]: https://www.reddit.com/r/rust
|
||||||
|
[discourse]: https://users.rust-lang.org
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
|||||||
+16
-6
@@ -43,10 +43,20 @@ fn main() {
|
|||||||
|
|
||||||
## Getting help
|
## Getting help
|
||||||
|
|
||||||
Serde developers live in the #serde channel on [`irc.mozilla.org`][irc]. The
|
Serde is one of the most widely used Rust libraries so any place that Rustaceans
|
||||||
\#rust channel is also a good resource with generally faster response time but
|
congregate will be able to help you out. For chat, consider trying the
|
||||||
less specific knowledge about Serde. If IRC is not your thing or you don't get a
|
[#general] or [#beginners] channels of the unofficial community Discord, the
|
||||||
good response, we are happy to respond to [GitHub issues][issues] as well.
|
[#rust-usage] channel of the official Rust Project Discord, or the
|
||||||
|
[#general][zulip] stream in Zulip. For asynchronous, consider the [\[rust\] tag
|
||||||
|
on StackOverflow][stackoverflow], the [/r/rust] subreddit which has a pinned
|
||||||
|
weekly easy questions post, or the Rust [Discourse forum][discourse]. It's
|
||||||
|
acceptable to file a support issue in this repo but they tend not to get as many
|
||||||
|
eyes as any of the above and may get closed without a response after some time.
|
||||||
|
|
||||||
[irc]: https://wiki.mozilla.org/IRC
|
[#general]: https://discord.com/channels/273534239310479360/274215136414400513
|
||||||
[issues]: https://github.com/serde-rs/serde/issues/new/choose
|
[#beginners]: https://discord.com/channels/273534239310479360/273541522815713281
|
||||||
|
[#rust-usage]: https://discord.com/channels/442252698964721669/443150878111694848
|
||||||
|
[zulip]: https://rust-lang.zulipchat.com/#narrow/stream/122651-general
|
||||||
|
[stackoverflow]: https://stackoverflow.com/questions/tagged/rust
|
||||||
|
[/r/rust]: https://www.reddit.com/r/rust
|
||||||
|
[discourse]: https://users.rust-lang.org
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.109" # remember to update html_root_url and serde_derive dependency
|
version = "1.0.111" # remember to update html_root_url and serde_derive dependency
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
description = "A generic serialization/deserialization framework"
|
description = "A generic serialization/deserialization framework"
|
||||||
@@ -14,7 +14,7 @@ include = ["Cargo.toml", "build.rs", "src/**/*.rs", "crates-io.md", "README.md",
|
|||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde_derive = { version = "=1.0.109", optional = true, path = "../serde_derive" }
|
serde_derive = { version = "=1.0.111", optional = true, path = "../serde_derive" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_derive = { version = "1.0", path = "../serde_derive" }
|
serde_derive = { version = "1.0", path = "../serde_derive" }
|
||||||
|
|||||||
+6
-1
@@ -53,6 +53,9 @@
|
|||||||
//! *(deserialization only)*
|
//! *(deserialization only)*
|
||||||
//! - [Envy Store], a way to deserialize [AWS Parameter Store] parameters into
|
//! - [Envy Store], a way to deserialize [AWS Parameter Store] parameters into
|
||||||
//! Rust structs. *(deserialization only)*
|
//! Rust structs. *(deserialization only)*
|
||||||
|
//! - [S-expressions], the textual representation of code and data used by the
|
||||||
|
//! Lisp language family.
|
||||||
|
//! - [D-Bus]'s binary wire format.
|
||||||
//!
|
//!
|
||||||
//! [JSON]: https://github.com/serde-rs/json
|
//! [JSON]: https://github.com/serde-rs/json
|
||||||
//! [Bincode]: https://github.com/TyOverby/bincode
|
//! [Bincode]: https://github.com/TyOverby/bincode
|
||||||
@@ -71,11 +74,13 @@
|
|||||||
//! [Envy Store]: https://github.com/softprops/envy-store
|
//! [Envy Store]: https://github.com/softprops/envy-store
|
||||||
//! [Cargo]: http://doc.crates.io/manifest.html
|
//! [Cargo]: http://doc.crates.io/manifest.html
|
||||||
//! [AWS Parameter Store]: https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html
|
//! [AWS Parameter Store]: https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html
|
||||||
|
//! [S-expressions]: https://github.com/rotty/lexpr-rs
|
||||||
|
//! [D-Bus]: https://docs.rs/zvariant
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Serde types in rustdoc of other crates get linked to here.
|
// Serde types in rustdoc of other crates get linked to here.
|
||||||
#![doc(html_root_url = "https://docs.rs/serde/1.0.109")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.111")]
|
||||||
// Support using Serde without the standard library!
|
// Support using Serde without the standard library!
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
// Unstable functionality only if the user asks for it. For tracking and
|
// Unstable functionality only if the user asks for it. For tracking and
|
||||||
|
|||||||
@@ -1562,7 +1562,7 @@ mod content {
|
|||||||
other.unexpected(),
|
other.unexpected(),
|
||||||
&"struct variant",
|
&"struct variant",
|
||||||
)),
|
)),
|
||||||
_ => Err(de::Error::invalid_type(
|
None => Err(de::Error::invalid_type(
|
||||||
de::Unexpected::UnitVariant,
|
de::Unexpected::UnitVariant,
|
||||||
&"struct variant",
|
&"struct variant",
|
||||||
)),
|
)),
|
||||||
@@ -2252,7 +2252,7 @@ mod content {
|
|||||||
other.unexpected(),
|
other.unexpected(),
|
||||||
&"struct variant",
|
&"struct variant",
|
||||||
)),
|
)),
|
||||||
_ => Err(de::Error::invalid_type(
|
None => Err(de::Error::invalid_type(
|
||||||
de::Unexpected::UnitVariant,
|
de::Unexpected::UnitVariant,
|
||||||
&"struct variant",
|
&"struct variant",
|
||||||
)),
|
)),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.109" # remember to update html_root_url
|
version = "1.0.111" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use syn::punctuated::{Pair, Punctuated};
|
|||||||
use syn::visit::{self, Visit};
|
use syn::visit::{self, Visit};
|
||||||
|
|
||||||
use internals::ast::{Container, Data};
|
use internals::ast::{Container, Data};
|
||||||
use internals::attr;
|
use internals::{attr, ungroup};
|
||||||
|
|
||||||
use proc_macro2::Span;
|
use proc_macro2::Span;
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ pub fn with_bound(
|
|||||||
}
|
}
|
||||||
impl<'ast> Visit<'ast> for FindTyParams<'ast> {
|
impl<'ast> Visit<'ast> for FindTyParams<'ast> {
|
||||||
fn visit_field(&mut self, field: &'ast syn::Field) {
|
fn visit_field(&mut self, field: &'ast syn::Field) {
|
||||||
if let syn::Type::Path(ty) = &field.ty {
|
if let syn::Type::Path(ty) = ungroup(&field.ty) {
|
||||||
if let Some(Pair::Punctuated(t, _)) = ty.path.segments.pairs().next() {
|
if let Some(Pair::Punctuated(t, _)) = ty.path.segments.pairs().next() {
|
||||||
if self.all_type_params.contains(&t.ident) {
|
if self.all_type_params.contains(&t.ident) {
|
||||||
self.associated_type_usage.push(ty);
|
self.associated_type_usage.push(ty);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use bound;
|
|||||||
use dummy;
|
use dummy;
|
||||||
use fragment::{Expr, Fragment, Match, Stmts};
|
use fragment::{Expr, Fragment, Match, Stmts};
|
||||||
use internals::ast::{Container, Data, Field, Style, Variant};
|
use internals::ast::{Container, Data, Field, Style, Variant};
|
||||||
use internals::{attr, Ctxt, Derive};
|
use internals::{attr, ungroup, Ctxt, Derive};
|
||||||
use pretend;
|
use pretend;
|
||||||
|
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
@@ -77,7 +77,7 @@ fn precondition(cx: &Ctxt, cont: &Container) {
|
|||||||
fn precondition_sized(cx: &Ctxt, cont: &Container) {
|
fn precondition_sized(cx: &Ctxt, cont: &Container) {
|
||||||
if let Data::Struct(_, fields) = &cont.data {
|
if let Data::Struct(_, fields) = &cont.data {
|
||||||
if let Some(last) = fields.last() {
|
if let Some(last) = fields.last() {
|
||||||
if let syn::Type::Slice(_) = *last.ty {
|
if let syn::Type::Slice(_) = ungroup(last.ty) {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
cont.original,
|
cont.original,
|
||||||
"cannot deserialize a dynamically sized struct",
|
"cannot deserialize a dynamically sized struct",
|
||||||
@@ -1381,7 +1381,7 @@ fn deserialize_adjacently_tagged_enum(
|
|||||||
_serde::export::Err(<__A::Error as _serde::de::Error>::missing_field(#content))
|
_serde::export::Err(<__A::Error as _serde::de::Error>::missing_field(#content))
|
||||||
};
|
};
|
||||||
let mut missing_content_fallthrough = quote!();
|
let mut missing_content_fallthrough = quote!();
|
||||||
let mut missing_content_arms = variants
|
let missing_content_arms = variants
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(_, variant)| !variant.attrs.skip_deserializing())
|
.filter(|&(_, variant)| !variant.attrs.skip_deserializing())
|
||||||
@@ -1409,8 +1409,8 @@ fn deserialize_adjacently_tagged_enum(
|
|||||||
__Field::#variant_index => #arm,
|
__Field::#variant_index => #arm,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.peekable();
|
.collect::<Vec<_>>();
|
||||||
if missing_content_arms.peek().is_some() {
|
if !missing_content_arms.is_empty() {
|
||||||
missing_content = quote! {
|
missing_content = quote! {
|
||||||
match __field {
|
match __field {
|
||||||
#(#missing_content_arms)*
|
#(#missing_content_arms)*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use internals::symbol::*;
|
use internals::symbol::*;
|
||||||
use internals::Ctxt;
|
use internals::{ungroup, Ctxt};
|
||||||
use proc_macro2::{Group, Span, TokenStream, TokenTree};
|
use proc_macro2::{Group, Span, TokenStream, TokenTree};
|
||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
@@ -222,6 +222,7 @@ pub struct Container {
|
|||||||
identifier: Identifier,
|
identifier: Identifier,
|
||||||
has_flatten: bool,
|
has_flatten: bool,
|
||||||
serde_path: Option<syn::Path>,
|
serde_path: Option<syn::Path>,
|
||||||
|
is_packed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Styles of representing an enum.
|
/// Styles of representing an enum.
|
||||||
@@ -592,6 +593,16 @@ impl Container {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut is_packed = false;
|
||||||
|
for attr in &item.attrs {
|
||||||
|
if attr.path.is_ident("repr") {
|
||||||
|
let _ = attr.parse_args_with(|input: ParseStream| {
|
||||||
|
is_packed |= input.parse::<Ident>()? == "packed";
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Container {
|
Container {
|
||||||
name: Name::from_attrs(unraw(&item.ident), ser_name, de_name, None),
|
name: Name::from_attrs(unraw(&item.ident), ser_name, de_name, None),
|
||||||
transparent: transparent.get(),
|
transparent: transparent.get(),
|
||||||
@@ -611,6 +622,7 @@ impl Container {
|
|||||||
identifier: decide_identifier(cx, item, field_identifier, variant_identifier),
|
identifier: decide_identifier(cx, item, field_identifier, variant_identifier),
|
||||||
has_flatten: false,
|
has_flatten: false,
|
||||||
serde_path: serde_path.get(),
|
serde_path: serde_path.get(),
|
||||||
|
is_packed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,6 +674,10 @@ impl Container {
|
|||||||
self.remote.as_ref()
|
self.remote.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_packed(&self) -> bool {
|
||||||
|
self.is_packed
|
||||||
|
}
|
||||||
|
|
||||||
pub fn identifier(&self) -> Identifier {
|
pub fn identifier(&self) -> Identifier {
|
||||||
self.identifier
|
self.identifier
|
||||||
}
|
}
|
||||||
@@ -1721,7 +1737,7 @@ fn is_implicitly_borrowed_reference(ty: &syn::Type) -> bool {
|
|||||||
// cow: Cow<'a, str>,
|
// cow: Cow<'a, str>,
|
||||||
// }
|
// }
|
||||||
fn is_cow(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
fn is_cow(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
||||||
let path = match ty {
|
let path = match ungroup(ty) {
|
||||||
syn::Type::Path(ty) => &ty.path,
|
syn::Type::Path(ty) => &ty.path,
|
||||||
_ => {
|
_ => {
|
||||||
return false;
|
return false;
|
||||||
@@ -1748,7 +1764,7 @@ fn is_cow(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_option(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
fn is_option(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
||||||
let path = match ty {
|
let path = match ungroup(ty) {
|
||||||
syn::Type::Path(ty) => &ty.path,
|
syn::Type::Path(ty) => &ty.path,
|
||||||
_ => {
|
_ => {
|
||||||
return false;
|
return false;
|
||||||
@@ -1795,7 +1811,7 @@ fn is_option(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
|||||||
// r: &'a str,
|
// r: &'a str,
|
||||||
// }
|
// }
|
||||||
fn is_reference(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
fn is_reference(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
||||||
match ty {
|
match ungroup(ty) {
|
||||||
syn::Type::Reference(ty) => ty.mutability.is_none() && elem(&ty.elem),
|
syn::Type::Reference(ty) => ty.mutability.is_none() && elem(&ty.elem),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
@@ -1806,14 +1822,14 @@ fn is_str(ty: &syn::Type) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_slice_u8(ty: &syn::Type) -> bool {
|
fn is_slice_u8(ty: &syn::Type) -> bool {
|
||||||
match ty {
|
match ungroup(ty) {
|
||||||
syn::Type::Slice(ty) => is_primitive_type(&ty.elem, "u8"),
|
syn::Type::Slice(ty) => is_primitive_type(&ty.elem, "u8"),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_primitive_type(ty: &syn::Type, primitive: &str) -> bool {
|
fn is_primitive_type(ty: &syn::Type, primitive: &str) -> bool {
|
||||||
match ty {
|
match ungroup(ty) {
|
||||||
syn::Type::Path(ty) => ty.qself.is_none() && is_primitive_path(&ty.path, primitive),
|
syn::Type::Path(ty) => ty.qself.is_none() && is_primitive_path(&ty.path, primitive),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use internals::ast::{Container, Data, Field, Style};
|
use internals::ast::{Container, Data, Field, Style};
|
||||||
use internals::attr::{Identifier, TagType};
|
use internals::attr::{Identifier, TagType};
|
||||||
use internals::{Ctxt, Derive};
|
use internals::{ungroup, Ctxt, Derive};
|
||||||
use syn::{Member, Type};
|
use syn::{Member, Type};
|
||||||
|
|
||||||
/// Cross-cutting checks that require looking at more than a single attrs
|
/// Cross-cutting checks that require looking at more than a single attrs
|
||||||
@@ -396,7 +396,7 @@ fn member_message(member: &Member) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn allow_transparent(field: &Field, derive: Derive) -> bool {
|
fn allow_transparent(field: &Field, derive: Derive) -> bool {
|
||||||
if let Type::Path(ty) = field.ty {
|
if let Type::Path(ty) = ungroup(&field.ty) {
|
||||||
if let Some(seg) = ty.path.segments.last() {
|
if let Some(seg) = ty.path.segments.last() {
|
||||||
if seg.ident == "PhantomData" {
|
if seg.ident == "PhantomData" {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -8,8 +8,17 @@ mod case;
|
|||||||
mod check;
|
mod check;
|
||||||
mod symbol;
|
mod symbol;
|
||||||
|
|
||||||
|
use syn::Type;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum Derive {
|
pub enum Derive {
|
||||||
Serialize,
|
Serialize,
|
||||||
Deserialize,
|
Deserialize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn ungroup(mut ty: &Type) -> &Type {
|
||||||
|
while let Type::Group(group) = ty {
|
||||||
|
ty = &group.elem;
|
||||||
|
}
|
||||||
|
ty
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
//!
|
//!
|
||||||
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.109")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.111")]
|
||||||
#![allow(unknown_lints, bare_trait_objects)]
|
#![allow(unknown_lints, bare_trait_objects)]
|
||||||
#![deny(clippy::all, clippy::pedantic)]
|
#![deny(clippy::all, clippy::pedantic)]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
|
|||||||
+18
-2
@@ -87,6 +87,9 @@ struct Parameters {
|
|||||||
|
|
||||||
/// Type has a `serde(remote = "...")` attribute.
|
/// Type has a `serde(remote = "...")` attribute.
|
||||||
is_remote: bool,
|
is_remote: bool,
|
||||||
|
|
||||||
|
/// Type has a repr(packed) attribute.
|
||||||
|
is_packed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parameters {
|
impl Parameters {
|
||||||
@@ -103,6 +106,8 @@ impl Parameters {
|
|||||||
None => cont.ident.clone().into(),
|
None => cont.ident.clone().into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let is_packed = cont.attrs.is_packed();
|
||||||
|
|
||||||
let generics = build_generics(cont);
|
let generics = build_generics(cont);
|
||||||
|
|
||||||
Parameters {
|
Parameters {
|
||||||
@@ -110,6 +115,7 @@ impl Parameters {
|
|||||||
this,
|
this,
|
||||||
generics,
|
generics,
|
||||||
is_remote,
|
is_remote,
|
||||||
|
is_packed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1238,9 +1244,19 @@ fn mut_if(is_mut: bool) -> Option<TokenStream> {
|
|||||||
fn get_member(params: &Parameters, field: &Field, member: &Member) -> TokenStream {
|
fn get_member(params: &Parameters, field: &Field, member: &Member) -> TokenStream {
|
||||||
let self_var = ¶ms.self_var;
|
let self_var = ¶ms.self_var;
|
||||||
match (params.is_remote, field.attrs.getter()) {
|
match (params.is_remote, field.attrs.getter()) {
|
||||||
(false, None) => quote!(&#self_var.#member),
|
(false, None) => {
|
||||||
|
if params.is_packed {
|
||||||
|
quote!(&{#self_var.#member})
|
||||||
|
} else {
|
||||||
|
quote!(&#self_var.#member)
|
||||||
|
}
|
||||||
|
}
|
||||||
(true, None) => {
|
(true, None) => {
|
||||||
let inner = quote!(&#self_var.#member);
|
let inner = if params.is_packed {
|
||||||
|
quote!(&{#self_var.#member})
|
||||||
|
} else {
|
||||||
|
quote!(&#self_var.#member)
|
||||||
|
};
|
||||||
let ty = field.ty;
|
let ty = field.ty;
|
||||||
quote!(_serde::private::ser::constrain::<#ty>(#inner))
|
quote!(_serde::private::ser::constrain::<#ty>(#inner))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.109" # remember to update html_root_url
|
version = "1.0.111" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
description = "Token De/Serializer for testing De/Serialize implementations"
|
description = "Token De/Serializer for testing De/Serialize implementations"
|
||||||
|
|||||||
@@ -144,7 +144,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.109")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.111")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
|
|||||||
@@ -701,6 +701,24 @@ fn test_gen() {
|
|||||||
#[serde(other)]
|
#[serde(other)]
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[repr(packed)]
|
||||||
|
struct Packed {
|
||||||
|
x: u8,
|
||||||
|
y: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! deriving {
|
||||||
|
($field:ty) => {
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct MacroRules<'a> {
|
||||||
|
field: $field,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
deriving!(&'a str);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user