Add `#[serde(skip_serializing)] to skip serializing some fields

Closes #99
This commit is contained in:
Erick Tryzelaar
2015-07-23 08:07:49 -07:00
parent 447d08bd91
commit b1cb5379de
5 changed files with 58 additions and 12 deletions
+15 -2
View File
@@ -16,14 +16,20 @@ pub enum FieldNames {
/// Represents field attribute information
pub struct FieldAttrs {
skip_serializing_field: bool,
names: FieldNames,
use_default: bool,
}
impl FieldAttrs {
/// Create a FieldAttr with a single default field name
pub fn new(default_value: bool, name: P<ast::Expr>) -> FieldAttrs {
pub fn new(
skip_serializing_field: bool,
default_value: bool,
name: P<ast::Expr>,
) -> FieldAttrs {
FieldAttrs {
skip_serializing_field: skip_serializing_field,
names: FieldNames::Global(name),
use_default: default_value,
}
@@ -31,12 +37,14 @@ impl FieldAttrs {
/// Create a FieldAttr with format specific field names
pub fn new_with_formats(
skip_serializing_field: bool,
default_value: bool,
default_name: P<ast::Expr>,
formats: HashMap<P<ast::Expr>, P<ast::Expr>>,
) -> FieldAttrs {
FieldAttrs {
names: FieldNames::Format {
skip_serializing_field: skip_serializing_field,
names: FieldNames::Format {
formats: formats,
default: default_name,
},
@@ -104,4 +112,9 @@ impl FieldAttrs {
pub fn use_default(&self) -> bool {
self.use_default
}
/// Predicate for ignoring a field when serializing a value
pub fn skip_serializing_field(&self) -> bool {
self.skip_serializing_field
}
}