Debian Codegraph @

src/trait_handlers/hash/hash_struct.rs

raw symbols SCIP
1 use quoterust-analyzer cargo quote 1.0.47 crate/::quoterust-analyzer cargo quote 1.0.47 quote!;
2 use synrust-analyzer cargo syn 2.0.119 crate/::{Datarust-analyzer cargo syn 2.0.119 derive/Data#, DeriveInputrust-analyzer cargo syn 2.0.119 derive/DeriveInput#, Metarust-analyzer cargo syn 2.0.119 attr/Meta#, Pathrust-analyzer cargo syn 2.0.119 path/Path#, Typerust-analyzer cargo syn 2.0.119 ty/Type#};
3
4 use superrust-analyzer cargo educe 0.6.0 trait_handlers/hash/::{
5 modelsrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/::{FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttributeBuilder#, TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/type_attribute/TypeAttributeBuilder#},
6 TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler#,
7 };
8 use craterust-analyzer cargo educe 0.6.0 crate/::{commonrust-analyzer cargo educe 0.6.0 common/::ident_indexrust-analyzer cargo educe 0.6.0 common/ident_index/::IdentOrIndexrust-analyzer cargo educe 0.6.0 common/ident_index/IdentOrIndex#, Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#};
9
10 pub(craterust-analyzer cargo educe 0.6.0 crate/) struct HashStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/hash/hash_struct/HashStructHandler#;
11
12 impl TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler# for HashStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/hash/hash_struct/HashStructHandler# {
13 #[inline]
14 fn trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/hash/hash_struct/impl#[HashStructHandler][TraitHandler]trait_meta_handler().(
15 ast: &DeriveInputrust-analyzer cargo syn 2.0.119 derive/DeriveInput#,
16 token_stream: &mut proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#,
17 traits: &[Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#],
18 meta: &Metarust-analyzer cargo syn 2.0.119 attr/Meta#,
19 ) -> synrust-analyzer cargo syn 2.0.119 crate/::Resultrust-analyzer cargo syn 2.0.119 error/Result#<()> {
20 let type_attribute =
21 TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/type_attribute/TypeAttributeBuilder# {
22 enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/type_attribute/TypeAttributeBuilder#enable_flag.: true, enable_unsaferust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/type_attribute/TypeAttributeBuilder#enable_unsafe.: false, enable_boundrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/type_attribute/TypeAttributeBuilder#enable_bound.: true
23 }
24 .build_from_hash_metarust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/type_attribute/impl#[TypeAttributeBuilder]build_from_hash_meta().(meta)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
25
26 let mut hash_types: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&Typerust-analyzer cargo syn 2.0.119 ty/Type#> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
27
28 let mut hash_token_stream = proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#::newrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream]new().();
29
30 if let Datarust-analyzer cargo syn 2.0.119 derive/Data#::Structrust-analyzer cargo syn 2.0.119 derive/Data#Struct#(data) = &ast.datarust-analyzer cargo syn 2.0.119 derive/DeriveInput#data. {
31 let built_in_hash: Pathrust-analyzer cargo syn 2.0.119 path/Path# = synrust-analyzer cargo syn 2.0.119 crate/::parse2rust-analyzer cargo syn 2.0.119 parse2().(quoterust-analyzer cargo quote 1.0.47 quote!!(::core::hash::Hash::hash)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
32
33 for (index, field) in data.fieldsrust-analyzer cargo syn 2.0.119 derive/DataStruct#fields..iterrust-analyzer cargo syn 2.0.119 data/impl#[Fields]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
34 let field_attribute = FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttributeBuilder# {
35 enable_ignorerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttributeBuilder#enable_ignore.: true,
36 enable_methodrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttributeBuilder#enable_method.: true,
37 }
38 .build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/impl#[FieldAttributeBuilder]build_from_attributes().(&field.attrsrust-analyzer cargo syn 2.0.119 data/Field#attrs., traits)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
39
40 if field_attribute.ignorerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttribute#ignore. {
41 continue;
42 }
43
44 let field_name = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ident) = field.identrust-analyzer cargo syn 2.0.119 data/Field#ident..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() {
45 IdentOrIndexrust-analyzer cargo educe 0.6.0 common/ident_index/IdentOrIndex#::fromrust-analyzer cargo educe 0.6.0 common/ident_index/impl#[IdentOrIndex][`From<&Ident>`]from().(ident)
46 } else {
47 IdentOrIndexrust-analyzer cargo educe 0.6.0 common/ident_index/IdentOrIndex#::fromrust-analyzer cargo educe 0.6.0 common/ident_index/impl#[IdentOrIndex][`From<usize>`]from().(index)
48 };
49
50 let hash = field_attribute.methodrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttribute#method..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| {
51 hash_types.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(&field.tyrust-analyzer cargo syn 2.0.119 data/Field#ty.);
52 &built_in_hash
53 });
54
55 hash_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!!( #hash(&self.#field_name, state); ));
56 }
57 }
58
59 let ident = &ast.identrust-analyzer cargo syn 2.0.119 derive/DeriveInput#ident.;
60
61 let bound = type_attribute.boundrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/type_attribute/TypeAttribute#bound..into_where_predicates_by_generic_parameters_check_typesrust-analyzer cargo educe 0.6.0 common/bound/impl#[Bound]into_where_predicates_by_generic_parameters_check_types().(
62 &ast.genericsrust-analyzer cargo syn 2.0.119 derive/DeriveInput#generics..paramsrust-analyzer cargo syn 2.0.119 generics/Generics#params.,
63 &synrust-analyzer cargo syn 2.0.119 crate/::parse2rust-analyzer cargo syn 2.0.119 parse2().(quoterust-analyzer cargo quote 1.0.47 quote!!(::core::hash::Hash)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
64 &hash_types,
65 &[],
66 );
67
68 let mut generics = ast.genericsrust-analyzer cargo syn 2.0.119 derive/DeriveInput#generics..clonerust-analyzer cargo syn 2.0.119 gen/clone/impl#[`crate::Generics`][Clone]clone().();
69 let where_clause = generics.make_where_clauserust-analyzer cargo syn 2.0.119 generics/impl#[Generics]make_where_clause().();
70
71 for where_predicate in bound {
72 where_clause.predicatesrust-analyzer cargo syn 2.0.119 generics/WhereClause#predicates..pushrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Punctuated<T, P>`]push().(where_predicate);
73 }
74
75 let (impl_generics, ty_generics, where_clause) = generics.split_for_implrust-analyzer cargo syn 2.0.119 generics/impl#[Generics]split_for_impl().();
76
77 token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! {
78 impl #impl_generics ::core::hash::Hash for #ident #ty_generics #where_clause {
79 #[inline]
80 fn hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
81 #hash_token_stream
82 }
83 }
84 });
85
86 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
87 }
88 }