1use 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)]
12pub struct Ignored;
13
14macro_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
24ignored!(FromGenericParam, from_generic_param, syn::GenericParam);
25ignored!(FromGenerics, from_generics, syn::Generics);
26ignored!(FromTypeParam, from_type_param, syn::TypeParam);
27ignored!(FromMeta, from_meta, syn::Meta);
28ignored!(FromDeriveInput, from_derive_input, syn::DeriveInput);
29ignored!(FromField, from_field, syn::Field);
30ignored!(FromVariant, from_variant, syn::Variant);
31
32impl 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
42impl 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