Debian Codegraph @

src/trait_handlers/hash/models/field_attribute.rs

raw symbols SCIP
1 use synrust-analyzer cargo syn 2.0.119 crate/::{punctuatedrust-analyzer cargo syn 2.0.119 punctuated/::Punctuatedrust-analyzer cargo syn 2.0.119 punctuated/Punctuated#, Attributerust-analyzer cargo syn 2.0.119 attr/Attribute#, Metarust-analyzer cargo syn 2.0.119 attr/Meta#, Pathrust-analyzer cargo syn 2.0.119 path/Path#, Tokenrust-analyzer cargo syn 2.0.119 token/Token!};
2
3 use craterust-analyzer cargo educe 0.6.0 crate/::{
4 commonrust-analyzer cargo educe 0.6.0 common/::{
5 ident_boolrust-analyzer cargo educe 0.6.0 common/ident_bool/::{meta_2_bool_allow_pathrust-analyzer cargo educe 0.6.0 common/ident_bool/meta_2_bool_allow_path()., meta_name_value_2_boolrust-analyzer cargo educe 0.6.0 common/ident_bool/meta_name_value_2_bool().},
6 pathrust-analyzer cargo educe 0.6.0 common/path/::meta_2_pathrust-analyzer cargo educe 0.6.0 common/path/meta_2_path().,
7 },
8 panicrust-analyzer cargo educe 0.6.0 panic/,
9 supported_traitsrust-analyzer cargo educe 0.6.0 supported_traits/::Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#,
10 };
11
12 pub(craterust-analyzer cargo educe 0.6.0 crate/) struct FieldAttributerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttribute# {
13 pub(craterust-analyzer cargo educe 0.6.0 crate/) ignorerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttribute#ignore.: bool,
14 pub(craterust-analyzer cargo educe 0.6.0 crate/) methodrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttribute#method.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Pathrust-analyzer cargo syn 2.0.119 path/Path#>,
15 }
16
17 pub(craterust-analyzer cargo educe 0.6.0 crate/) struct FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttributeBuilder# {
18 pub(craterust-analyzer cargo educe 0.6.0 crate/) enable_ignorerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttributeBuilder#enable_ignore.: bool,
19 pub(craterust-analyzer cargo educe 0.6.0 crate/) enable_methodrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttributeBuilder#enable_method.: bool,
20 }
21
22 impl FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttributeBuilder# {
23 pub(craterust-analyzer cargo educe 0.6.0 crate/) fn build_from_hash_metarust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/impl#[FieldAttributeBuilder]build_from_hash_meta().(&self, meta: &Metarust-analyzer cargo syn 2.0.119 attr/Meta#) -> synrust-analyzer cargo syn 2.0.119 crate/::Resultrust-analyzer cargo syn 2.0.119 error/Result#<FieldAttributerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttribute#> {
24 debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(meta.pathrust-analyzer cargo syn 2.0.119 attr/impl#[Meta]path().().is_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]is_ident().("Hash"));
25
26 let mut ignore = false;
27 let mut method = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
28
29 let correct_usage_for_partial_eq_attribute = {
30 let mut usage = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
31
32 if self.enable_ignorerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttributeBuilder#enable_ignore. {
33 usage.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(stringifyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/stringify!!(#[educe(Hash = false)]));
34 usage.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(stringifyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/stringify!!(#[educe(Hash(ignore))]));
35 }
36
37 if self.enable_methodrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttributeBuilder#enable_method. {
38 usage.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(stringifyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/stringify!!(#[educe(Hash(method(path_to_method)))]));
39 }
40
41 usage
42 };
43
44 match meta {
45 Metarust-analyzer cargo syn 2.0.119 attr/Meta#::Pathrust-analyzer cargo syn 2.0.119 attr/Meta#Path#(_) => {
46 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(panicrust-analyzer cargo educe 0.6.0 panic/::attribute_incorrect_formatrust-analyzer cargo educe 0.6.0 panic/attribute_incorrect_format().(
47 meta.pathrust-analyzer cargo syn 2.0.119 attr/impl#[Meta]path().().get_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]get_ident().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
48 &correct_usage_for_partial_eq_attribute,
49 ));
50 },
51 Metarust-analyzer cargo syn 2.0.119 attr/Meta#::NameValuerust-analyzer cargo syn 2.0.119 attr/Meta#NameValue#(name_value) => {
52 if self.enable_ignorerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttributeBuilder#enable_ignore. {
53 ignore = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().meta_name_value_2_boolrust-analyzer cargo educe 0.6.0 common/ident_bool/meta_name_value_2_bool().(name_value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
54 } else {
55 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(panicrust-analyzer cargo educe 0.6.0 panic/::attribute_incorrect_formatrust-analyzer cargo educe 0.6.0 panic/attribute_incorrect_format().(
56 meta.pathrust-analyzer cargo syn 2.0.119 attr/impl#[Meta]path().().get_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]get_ident().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
57 &correct_usage_for_partial_eq_attribute,
58 ));
59 }
60 },
61 Metarust-analyzer cargo syn 2.0.119 attr/Meta#::Listrust-analyzer cargo syn 2.0.119 attr/Meta#List#(list) => {
62 let result =
63 list.parse_args_withrust-analyzer cargo syn 2.0.119 attr/impl#[MetaList]parse_args_with().(Punctuatedrust-analyzer cargo syn 2.0.119 punctuated/Punctuated#::<Metarust-analyzer cargo syn 2.0.119 attr/Meta#, Tokenrust-analyzer cargo syn 2.0.119 token/Token!![,]>::parse_terminatedrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Punctuated<T, P>`]parse_terminated().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
64
65 let mut ignore_is_set = false;
66 let mut method_is_set = false;
67
68 let mut handler = |meta: Metarust-analyzer cargo syn 2.0.119 attr/Meta#| -> synrust-analyzer cargo syn 2.0.119 crate/::Resultrust-analyzer cargo syn 2.0.119 error/Result#<bool> {
69 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ident) = meta.pathrust-analyzer cargo syn 2.0.119 attr/impl#[Meta]path().().get_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]get_ident().() {
70 match ident.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() {
71 "ignore" => {
72 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.enable_ignorerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttributeBuilder#enable_ignore. {
73 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false);
74 }
75
76 let v = meta_2_bool_allow_pathrust-analyzer cargo educe 0.6.0 common/ident_bool/meta_2_bool_allow_path().(&meta)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
77
78 if ignore_is_set {
79 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(panicrust-analyzer cargo educe 0.6.0 panic/::parameter_resetrust-analyzer cargo educe 0.6.0 panic/parameter_reset().(ident));
80 }
81
82 ignore_is_set = true;
83
84 ignore = v;
85
86 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true);
87 },
88 "method" => {
89 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.enable_methodrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttributeBuilder#enable_method. {
90 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false);
91 }
92
93 let v = meta_2_pathrust-analyzer cargo educe 0.6.0 common/path/meta_2_path().(&meta)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
94
95 if method_is_set {
96 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(panicrust-analyzer cargo educe 0.6.0 panic/::parameter_resetrust-analyzer cargo educe 0.6.0 panic/parameter_reset().(ident));
97 }
98
99 method_is_set = true;
100
101 method = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v);
102
103 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true);
104 },
105 _ => (),
106 }
107 }
108
109 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false)
110 };
111
112 for p in result {
113 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().handler(p)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
114 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(panicrust-analyzer cargo educe 0.6.0 panic/::attribute_incorrect_formatrust-analyzer cargo educe 0.6.0 panic/attribute_incorrect_format().(
115 meta.pathrust-analyzer cargo syn 2.0.119 attr/impl#[Meta]path().().get_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]get_ident().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
116 &correct_usage_for_partial_eq_attribute,
117 ));
118 }
119 }
120 },
121 }
122
123 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(FieldAttributerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttribute# {
124 ignorerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttribute#ignore.,
125 methodrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttribute#method.,
126 })
127 }
128
129 pub(craterust-analyzer cargo educe 0.6.0 crate/) fn build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/impl#[FieldAttributeBuilder]build_from_attributes().(
130 &self,
131 attributes: &[Attributerust-analyzer cargo syn 2.0.119 attr/Attribute#],
132 traits: &[Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#],
133 ) -> synrust-analyzer cargo syn 2.0.119 crate/::Resultrust-analyzer cargo syn 2.0.119 error/Result#<FieldAttributerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttribute#> {
134 let mut output = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
135
136 for attribute in attributes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
137 let path = attribute.pathrust-analyzer cargo syn 2.0.119 attr/impl#[Attribute]path().();
138
139 if path.is_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]is_ident().("educe") {
140 if let Metarust-analyzer cargo syn 2.0.119 attr/Meta#::Listrust-analyzer cargo syn 2.0.119 attr/Meta#List#(list) = &attribute.metarust-analyzer cargo syn 2.0.119 attr/Attribute#meta. {
141 let result =
142 list.parse_args_withrust-analyzer cargo syn 2.0.119 attr/impl#[MetaList]parse_args_with().(Punctuatedrust-analyzer cargo syn 2.0.119 punctuated/Punctuated#::<Metarust-analyzer cargo syn 2.0.119 attr/Meta#, Tokenrust-analyzer cargo syn 2.0.119 token/Token!![,]>::parse_terminatedrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Punctuated<T, P>`]parse_terminated().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
143
144 for meta in result {
145 let path = meta.pathrust-analyzer cargo syn 2.0.119 attr/impl#[Meta]path().();
146
147 let t = match Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::from_pathrust-analyzer cargo educe 0.6.0 supported_traits/impl#[Trait]from_path().(path) {
148 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) => t,
149 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(panicrust-analyzer cargo educe 0.6.0 panic/::unsupported_traitrust-analyzer cargo educe 0.6.0 panic/unsupported_trait().(meta.pathrust-analyzer cargo syn 2.0.119 attr/impl#[Meta]path().())),
150 };
151
152 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().traits.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&t) {
153 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(panicrust-analyzer cargo educe 0.6.0 panic/::trait_not_usedrust-analyzer cargo educe 0.6.0 panic/trait_not_used().(path.get_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]get_ident().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()));
154 }
155
156 if t rust-analyzer cargo educe 0.6.0 supported_traits/impl#[Trait][`PartialEq<Self>`]eq().==rust-analyzer cargo educe 0.6.0 supported_traits/impl#[Trait][`PartialEq<Self>`]eq(). rust-analyzer cargo educe 0.6.0 supported_traits/impl#[Trait][`PartialEq<Self>`]eq().Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::Hashrust-analyzer cargo educe 0.6.0 supported_traits/Trait#Hash# {
157 if output.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
158 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(panicrust-analyzer cargo educe 0.6.0 panic/::reuse_a_traitrust-analyzer cargo educe 0.6.0 panic/reuse_a_trait().(path.get_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]get_ident().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()));
159 }
160
161 output = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.build_from_hash_metarust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/impl#[FieldAttributeBuilder]build_from_hash_meta().(&meta)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().);
162 }
163 }
164 }
165 }
166 }
167
168 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(output.unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(FieldAttributerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttribute# {
169 ignorerust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttribute#ignore.: false, methodrust-analyzer cargo educe 0.6.0 trait_handlers/hash/models/field_attribute/FieldAttribute#method.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
170 }))
171 }
172 }