Debian Codegraph @

src/trait_handlers/ord/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/ord/::{
7 modelsrust-analyzer cargo educe 0.6.0 trait_handlers/ord/models/::{FieldAttributerust-analyzer cargo educe 0.6.0 trait_handlers/ord/models/field_attribute/FieldAttribute#, FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/ord/models/field_attribute/FieldAttributeBuilder#, TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/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 OrdStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/ord/ord_struct/OrdStructHandler#;
13
14 impl TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler# for OrdStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/ord/ord_struct/OrdStructHandler# {
15 #[inline]
16 fn trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/ord/ord_struct/impl#[OrdStructHandler][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/ord/models/type_attribute/TypeAttributeBuilder# {
23 enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/ord/models/type_attribute/TypeAttributeBuilder#enable_flag.: true, enable_boundrust-analyzer cargo educe 0.6.0 trait_handlers/ord/models/type_attribute/TypeAttributeBuilder#enable_bound.: true
24 }
25 .build_from_ord_metarust-analyzer cargo educe 0.6.0 trait_handlers/ord/models/type_attribute/impl#[TypeAttributeBuilder]build_from_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 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 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/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/ord/models/field_attribute/FieldAttributeBuilder# {
36 enable_ignorerust-analyzer cargo educe 0.6.0 trait_handlers/ord/models/field_attribute/FieldAttributeBuilder#enable_ignore.: true,
37 enable_methodrust-analyzer cargo educe 0.6.0 trait_handlers/ord/models/field_attribute/FieldAttributeBuilder#enable_method.: true,
38 enable_rankrust-analyzer cargo educe 0.6.0 trait_handlers/ord/models/field_attribute/FieldAttributeBuilder#enable_rank.: true,
39 rankrust-analyzer cargo educe 0.6.0 trait_handlers/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/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/ord/models/field_attribute/FieldAttribute#ignore. {
44 continue;
45 }
46
47 let rank = field_attribute.rankrust-analyzer cargo educe 0.6.0 trait_handlers/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/ord/::panicrust-analyzer cargo educe 0.6.0 trait_handlers/ord/panic/::reuse_a_rankrust-analyzer cargo educe 0.6.0 trait_handlers/ord/panic/reuse_a_rank().(
51 field_attribute.rank_spanrust-analyzer cargo educe 0.6.0 trait_handlers/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_cmp: 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::cmp::Ord::cmp)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
60
61 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().() {
62 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);
63
64 let cmp = field_attribute.methodrust-analyzer cargo educe 0.6.0 trait_handlers/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().(|| {
65 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.);
66
67 &built_in_cmp
68 });
69
70 cmp_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! {
71 match #cmp(&self.#field_name, &other.#field_name) {
72 ::core::cmp::Ordering::Equal => (),
73 ::core::cmp::Ordering::Greater => return ::core::cmp::Ordering::Greater,
74 ::core::cmp::Ordering::Less => return ::core::cmp::Ordering::Less,
75 }
76 });
77 }
78 }
79
80 let ident = &ast.identrust-analyzer cargo syn 2.0.119 derive/DeriveInput#ident.;
81
82 let bound = type_attribute.boundrust-analyzer cargo educe 0.6.0 trait_handlers/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().(
83 &ast.genericsrust-analyzer cargo syn 2.0.119 derive/DeriveInput#generics..paramsrust-analyzer cargo syn 2.0.119 generics/Generics#params.,
84 &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::Ord)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
85 &ord_types,
86 &craterust-analyzer cargo educe 0.6.0 crate/::trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::ordrust-analyzer cargo educe 0.6.0 trait_handlers/ord/::supertraitsrust-analyzer cargo educe 0.6.0 trait_handlers/ord/supertraits().(traits),
87 );
88
89 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().();
90 let where_clause = generics.make_where_clauserust-analyzer cargo syn 2.0.119 generics/impl#[Generics]make_where_clause().();
91
92 for where_predicate in bound {
93 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);
94 }
95
96 let (impl_generics, ty_generics, where_clause) = generics.split_for_implrust-analyzer cargo syn 2.0.119 generics/impl#[Generics]split_for_impl().();
97
98 token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! {
99 impl #impl_generics ::core::cmp::Ord for #ident #ty_generics #where_clause {
100 #[inline]
101 fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
102 #cmp_token_stream
103
104 ::core::cmp::Ordering::Equal
105 }
106 }
107 });
108
109 #[cfg(feature = "PartialOrd")]
110 if traits.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::PartialOrdrust-analyzer cargo educe 0.6.0 supported_traits/Trait#PartialOrd#) {
111 token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! {
112 impl #impl_generics ::core::cmp::PartialOrd for #ident #ty_generics #where_clause {
113 #[inline]
114 fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
115 Some(::core::cmp::Ord::cmp(self, other))
116 }
117 }
118 });
119 }
120
121 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
122 }
123 }