s/disallow_unknown/deny_unknown_fields/
This commit is contained in:
parent
bfac1a581c
commit
8c57f433ff
@ -600,7 +600,7 @@ Structure Annotations:
|
||||
|
||||
| Annotation | Function |
|
||||
| ---------- | -------- |
|
||||
| `#[serde(disallow_unknown)` | Always error during serialization when encountering unknown fields. When absent, unknown fields are ignored for self-describing formats like JSON. |
|
||||
| `#[serde(deny_unknown_fields)` | Always error during serialization when encountering unknown fields. When absent, unknown fields are ignored for self-describing formats like JSON. |
|
||||
|
||||
|
||||
Serialization Formats Using Serde
|
||||
|
@ -247,23 +247,23 @@ impl<'a> FieldAttrsBuilder<'a> {
|
||||
/// Represents container (e.g. struct) attribute information
|
||||
#[derive(Debug)]
|
||||
pub struct ContainerAttrs {
|
||||
disallow_unknown: bool,
|
||||
deny_unknown_fields: bool,
|
||||
}
|
||||
|
||||
impl ContainerAttrs {
|
||||
pub fn disallow_unknown(&self) -> bool {
|
||||
self.disallow_unknown
|
||||
pub fn deny_unknown_fields(&self) -> bool {
|
||||
self.deny_unknown_fields
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ContainerAttrsBuilder {
|
||||
disallow_unknown: bool,
|
||||
deny_unknown_fields: bool,
|
||||
}
|
||||
|
||||
impl ContainerAttrsBuilder {
|
||||
pub fn new() -> ContainerAttrsBuilder {
|
||||
ContainerAttrsBuilder {
|
||||
disallow_unknown: false,
|
||||
deny_unknown_fields: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,8 +285,8 @@ impl ContainerAttrsBuilder {
|
||||
|
||||
pub fn meta_item(self, meta_item: &P<ast::MetaItem>) -> ContainerAttrsBuilder {
|
||||
match meta_item.node {
|
||||
ast::MetaWord(ref name) if name == &"disallow_unknown" => {
|
||||
self.disallow_unknown()
|
||||
ast::MetaWord(ref name) if name == &"deny_unknown_fields" => {
|
||||
self.deny_unknown_fields()
|
||||
}
|
||||
_ => {
|
||||
// Ignore unknown meta variables for now.
|
||||
@ -295,14 +295,14 @@ impl ContainerAttrsBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disallow_unknown(mut self) -> ContainerAttrsBuilder {
|
||||
self.disallow_unknown = true;
|
||||
pub fn deny_unknown_fields(mut self) -> ContainerAttrsBuilder {
|
||||
self.deny_unknown_fields = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> ContainerAttrs {
|
||||
ContainerAttrs {
|
||||
disallow_unknown: self.disallow_unknown,
|
||||
deny_unknown_fields: self.deny_unknown_fields,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -567,7 +567,7 @@ fn deserialize_item_enum(
|
||||
const VARIANTS: &'static [&'static str] = $variants_expr;
|
||||
).unwrap();
|
||||
|
||||
let ignored_arm = if !container_attrs.disallow_unknown() {
|
||||
let ignored_arm = if !container_attrs.deny_unknown_fields() {
|
||||
Some(quote_arm!(cx, __Field::__ignore => { Err(::serde::de::Error::end_of_stream()) }))
|
||||
} else {
|
||||
None
|
||||
@ -800,7 +800,7 @@ fn deserialize_field_visitor(
|
||||
.map(|i| builder.id(format!("__field{}", i)))
|
||||
.collect();
|
||||
|
||||
let ignore_variant = if !container_attrs.disallow_unknown() {
|
||||
let ignore_variant = if !container_attrs.deny_unknown_fields() {
|
||||
let skip_ident = builder.id("__ignore");
|
||||
Some(builder.variant(skip_ident).unit())
|
||||
} else {
|
||||
@ -848,7 +848,7 @@ fn deserialize_field_visitor(
|
||||
})
|
||||
.collect();
|
||||
|
||||
let fallthrough_arm_expr = if !container_attrs.disallow_unknown() {
|
||||
let fallthrough_arm_expr = if !container_attrs.deny_unknown_fields() {
|
||||
quote_expr!(cx, Ok(__Field::__ignore))
|
||||
} else {
|
||||
quote_expr!(cx, Err(::serde::de::Error::unknown_field(value)))
|
||||
@ -1012,7 +1012,7 @@ fn deserialize_map(
|
||||
|
||||
|
||||
// Visit ignored values to consume them
|
||||
let ignored_arm = if !container_attrs.disallow_unknown() {
|
||||
let ignored_arm = if !container_attrs.deny_unknown_fields() {
|
||||
Some(quote_arm!(cx,
|
||||
_ => { try!(visitor.visit_value::<::serde::de::impls::IgnoredAny>()); }
|
||||
))
|
||||
|
@ -17,7 +17,7 @@ struct Default {
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(disallow_unknown)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct DisallowUnknown {
|
||||
a1: i32,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user