Currently, #[traverse(skip)] can be added to a struct and its fields, as well as an enum, its variants, and its fields:
|
fn traverse_variant(v: Variant, mutable: bool) -> Result<TokenStream> { |
|
let mut params = Params::from_attrs(v.attrs, "traverse")?; |
|
params.validate(&["skip"])?; |
|
if params.param("skip")?.map(Param::unit).is_some() { |
|
return Ok(TokenStream::new()); |
|
} |
|
Ok(if params.param("skip")?.map(Param::unit).is_some() { |
|
quote! { #field_name: _ } |
|
} else { |
|
field_name.into_token_stream() |
|
}) |
|
fn traverse_field(value: &TokenStream, field: Field, mutable: bool) -> Result<TokenStream> { |
|
let mut params = Params::from_attrs(field.attrs, "traverse")?; |
|
params.validate(&["skip", "with"])?; |
|
|
|
if params.param("skip")?.map(Param::unit).is_some() { |
|
return Ok(TokenStream::new()); |
|
let mut params = Params::from_attrs(input.attrs, "traverse")?; |
|
params.validate(&["skip"])?; |
|
|
|
let skip_visit_self = params |
|
.param("skip")? |
|
.map(Param::unit) |
|
.transpose()? |
|
.is_some(); |
While skip variants and fields work well, "skip visit self" looks weird.
Typically, when you derive a struct as Traversable, you would like to visit it, of course.
Besides, a skip_all parameter to skip all fields of a struct can be useful, but it may be dangerous as well.
We need to decide what #[traverse(skip)] should be possibly noted a struct/enum to skip self, and whether to support #[traverse(skip_all)] before 1.0.
Currently,
#[traverse(skip)]can be added to a struct and its fields, as well as an enum, its variants, and its fields:traversable/traversable-derive/src/lib.rs
Lines 331 to 336 in 5c6468c
traversable/traversable-derive/src/lib.rs
Lines 371 to 375 in 5c6468c
traversable/traversable-derive/src/lib.rs
Lines 404 to 409 in 5c6468c
traversable/traversable-derive/src/lib.rs
Lines 207 to 214 in 5c6468c
While skip variants and fields work well, "skip visit self" looks weird.
Typically, when you derive a struct as
Traversable, you would like to visit it, of course.Besides, a
skip_allparameter to skip all fields of a struct can be useful, but it may be dangerous as well.We need to decide what
#[traverse(skip)]should be possibly noted a struct/enum to skip self, and whether to support#[traverse(skip_all)]before 1.0.