Debian Codegraph @

src/trait_handlers/partial_ord/partial_ord_struct.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#;
2
3 use quoterust-analyzer cargo quote 1.0.47 crate/::quoterust-analyzer cargo quote 1.0.47 quote!;
4 use synrust-analyzer cargo syn 2.0.119 crate/::{spannedrust-analyzer cargo syn 2.0.119 spanned/::Spannedrust-analyzer cargo syn 2.0.119 spanned/Spanned#, Datarust-analyzer cargo syn 2.0.119 derive/Data#, DeriveInputrust-analyzer cargo syn 2.0.119 derive/DeriveInput#, Fieldrust-analyzer cargo syn 2.0.119 data/Field#, 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#};
5
6 use superrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/::{
7 modelsrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/::{FieldAttributerust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/field_attribute/FieldAttribute#, FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/field_attribute/FieldAttributeBuilder#, TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/type_attribute/TypeAttributeBuilder#},
8 TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler#,
9 };
10 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#};
11
12 pub(craterust-analyzer cargo educe 0.6.0 crate/) struct PartialOrdStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/partial_ord_struct/PartialOrdStructHandler#;
13
14 impl TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler# for PartialOrdStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/partial_ord_struct/PartialOrdStructHandler# {
15 #[inline]
16 fn trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/partial_ord_struct/impl#[PartialOrdStructHandler][TraitHandler]trait_meta_handler().(
17 ast: &DeriveInputrust-analyzer cargo syn 2.0.119 derive/DeriveInput#,
18 token_stream: &mut proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#,
19 traits: &[Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#],
20 meta: &Metarust-analyzer cargo syn 2.0.119 attr/Meta#,
21 ) -> synrust-analyzer cargo syn 2.0.119 crate/::Resultrust-analyzer cargo syn 2.0.119 error/Result#<()> {
22 let type_attribute = TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/type_attribute/TypeAttributeBuilder# {
23 enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/type_attribute/TypeAttributeBuilder#enable_flag.: true, enable_boundrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/type_attribute/TypeAttributeBuilder#enable_bound.: true
24 }
25 .build_from_partial_ord_metarust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/type_attribute/impl#[TypeAttributeBuilder]build_from_partial_ord_meta().(meta)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
26
27 let mut partial_ord_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().();
28
29 let mut partial_cmp_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().();
30
31 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. {
32 let mut fields: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<isize, (usize, &Fieldrust-analyzer cargo syn 2.0.119 data/Field#, FieldAttributerust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/field_attribute/FieldAttribute#)> = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().();
33
34 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().() {
35 let field_attribute = FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/field_attribute/FieldAttributeBuilder# {
36 enable_ignorerust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/field_attribute/FieldAttributeBuilder#enable_ignore.: true,
37 enable_methodrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/field_attribute/FieldAttributeBuilder#enable_method.: true,
38 enable_rankrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/field_attribute/FieldAttributeBuilder#enable_rank.: true,
39 rankrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/field_attribute/FieldAttributeBuilder#rank.: isize::MINrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[isize]MIN. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().index as isize,
40 }
41 .build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/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().;
42
43 if field_attribute.ignorerust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/field_attribute/FieldAttribute#ignore. {
44 continue;
45 }
46
47 let rank = field_attribute.rankrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/field_attribute/FieldAttribute#rank.;
48
49 if fields.contains_keyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]contains_key().(&rank) {
50 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(superrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/::panicrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/panic/::reuse_a_rankrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/panic/reuse_a_rank().(
51 field_attribute.rank_spanrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/models/field_attribute/FieldAttribute#rank_span..unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| field.spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().()),
52 rank,
53 ));
54 }
55
56 fields.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(rank, (index, field, field_attribute));
57 }
58
59 let built_in_partial_cmp: Pathrust-analyzer cargo syn 2.0.119 path/Path# =
60 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::cmp::PartialOrd::partial_cmp)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
61
62 for (index, field, field_attribute) in fields.valuesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]values().() {
63 let field_name = IdentOrIndexrust-analyzer cargo educe 0.6.0 common/ident_index/IdentOrIndex#::from_ident_with_indexrust-analyzer cargo educe 0.6.0 common/ident_index/impl#[IdentOrIndex]from_ident_with_index().(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().(), *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().index);
64
65 let partial_cmp = field_attribute.methodrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/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().(|| {
66 partial_ord_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.);
67
68 &built_in_partial_cmp
69 });
70
71 partial_cmp_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! {
72 match #partial_cmp(&self.#field_name, &other.#field_name) {
73 Some(::core::cmp::Ordering::Equal) => (),
74 Some(::core::cmp::Ordering::Greater) => return Some(::core::cmp::Ordering::Greater),
75 Some(::core::cmp::Ordering::Less) => return Some(::core::cmp::Ordering::Less),
76 None => return None,
77 }
78 });
79 }
80 }
81
82 let ident = &ast.identrust-analyzer cargo syn 2.0.119 derive/DeriveInput#ident.;
83
84 let bound = type_attribute.boundrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/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().(
85 &ast.genericsrust-analyzer cargo syn 2.0.119 derive/DeriveInput#generics..paramsrust-analyzer cargo syn 2.0.119 generics/Generics#params.,
86 &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::cmp::PartialOrd)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
87 &partial_ord_types,
88 &[quoterust-analyzer cargo quote 1.0.47 quote!! {::core::cmp::PartialEq}],
89 );
90
91 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().();
92 let where_clause = generics.make_where_clauserust-analyzer cargo syn 2.0.119 generics/impl#[Generics]make_where_clause().();
93
94 for where_predicate in bound {
95 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);
96 }
97
98 let (impl_generics, ty_generics, where_clause) = generics.split_for_implrust-analyzer cargo syn 2.0.119 generics/impl#[Generics]split_for_impl().();
99
100 token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! {
101 impl #impl_generics ::core::cmp::PartialOrd for #ident #ty_generics #where_clause {
102 #[inline]
103 fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
104 #partial_cmp_token_stream
105
106 Some(::core::cmp::Ordering::Equal)
107 }
108 }
109 });
110
111 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
112 }
113 }