1 | use crate::{ |
2 | usage::{self, UsesLifetimes, UsesTypeParams}, |
3 | FromDeriveInput, FromField, FromGenericParam, FromGenerics, FromMeta, FromTypeParam, |
4 | FromVariant, Result, |
5 | }; |
6 | |
7 | /// An efficient way of discarding data from a syntax element. |
8 | /// |
9 | /// All syntax elements will be successfully read into |
10 | /// the `Ignored` struct, with all properties discarded. |
11 | #[derive (Debug, Clone, Copy, PartialEq, Eq, Hash, Default)] |
12 | pub struct Ignored; |
13 | |
14 | macro_rules! ignored { |
15 | ($trayt:ident, $method:ident, $syn:path) => { |
16 | impl $trayt for Ignored { |
17 | fn $method(_: &$syn) -> Result<Self> { |
18 | Ok(Ignored) |
19 | } |
20 | } |
21 | }; |
22 | } |
23 | |
24 | ignored!(FromGenericParam, from_generic_param, syn::GenericParam); |
25 | ignored!(FromGenerics, from_generics, syn::Generics); |
26 | ignored!(FromTypeParam, from_type_param, syn::TypeParam); |
27 | ignored!(FromMeta, from_meta, syn::Meta); |
28 | ignored!(FromDeriveInput, from_derive_input, syn::DeriveInput); |
29 | ignored!(FromField, from_field, syn::Field); |
30 | ignored!(FromVariant, from_variant, syn::Variant); |
31 | |
32 | impl UsesTypeParams for Ignored { |
33 | fn uses_type_params<'a>( |
34 | &self, |
35 | _opts: &usage::Options, |
36 | _: &'a usage::IdentSet, |
37 | ) -> usage::IdentRefSet<'a> { |
38 | Default::default() |
39 | } |
40 | } |
41 | |
42 | impl UsesLifetimes for Ignored { |
43 | fn uses_lifetimes<'a>( |
44 | &self, |
45 | _opts: &usage::Options, |
46 | _: &'a usage::LifetimeSet, |
47 | ) -> usage::LifetimeRefSet<'a> { |
48 | Default::default() |
49 | } |
50 | } |
51 | |