| 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/::{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#}; |
| 3 | |
| 4 | use superrust-analyzer cargo educe 0.6.0 trait_handlers/deref/::{ |
| 5 | modelsrust-analyzer cargo educe 0.6.0 trait_handlers/deref/models/::{FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/deref/models/field_attribute/FieldAttributeBuilder#, TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/deref/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/::{ |
| 9 | 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#, r#typerust-analyzer cargo educe 0.6.0 common/`r#type`/::dereference_changedrust-analyzer cargo educe 0.6.0 common/`r#type`/dereference_changed().}, |
| 10 | Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#, |
| 11 | }; |
| 12 | |
| 13 | pub(craterust-analyzer cargo educe 0.6.0 crate/) struct DerefStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/deref/deref_struct/DerefStructHandler#; |
| 14 | |
| 15 | impl TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler# for DerefStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/deref/deref_struct/DerefStructHandler# { |
| 16 | #[inline] |
| 17 | fn trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/deref/deref_struct/impl#[DerefStructHandler][TraitHandler]trait_meta_handler().( |
| 18 | ast: &DeriveInputrust-analyzer cargo syn 2.0.119 derive/DeriveInput#, |
| 19 | token_stream: &mut proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#, |
| 20 | traits: &[Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#], |
| 21 | meta: &Metarust-analyzer cargo syn 2.0.119 attr/Meta#, |
| 22 | ) -> synrust-analyzer cargo syn 2.0.119 crate/::Resultrust-analyzer cargo syn 2.0.119 error/Result#<()> { |
| 23 | let _ = TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/deref/models/type_attribute/TypeAttributeBuilder# { |
| 24 | enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/deref/models/type_attribute/TypeAttributeBuilder#enable_flag.: true |
| 25 | } |
| 26 | .build_from_deref_metarust-analyzer cargo educe 0.6.0 trait_handlers/deref/models/type_attribute/impl#[TypeAttributeBuilder]build_from_deref_meta().(meta)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 27 | |
| 28 | let mut target_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 | let mut deref_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 (index, field) = { |
| 33 | let fields = &data.fieldsrust-analyzer cargo syn 2.0.119 derive/DataStruct#fields.; |
| 34 | |
| 35 | if fields.lenrust-analyzer cargo syn 2.0.119 data/impl#[Fields]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 { |
| 36 | let field = fields.into_iterrust-analyzer cargo syn 2.0.119 data/impl#[`&'a Fields`][IntoIterator]into_iter().().nextrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Iter<'a, T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 37 | |
| 38 | let _ = FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/deref/models/field_attribute/FieldAttributeBuilder# { |
| 39 | enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/deref/models/field_attribute/FieldAttributeBuilder#enable_flag.: true |
| 40 | } |
| 41 | .build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/deref/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 | (0usize, field) |
| 44 | } else { |
| 45 | let mut deref_field: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(usize, &Fieldrust-analyzer cargo syn 2.0.119 data/Field#)> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 46 | |
| 47 | for (index, field) in 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().() { |
| 48 | let field_attribute = FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/deref/models/field_attribute/FieldAttributeBuilder# { |
| 49 | enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/deref/models/field_attribute/FieldAttributeBuilder#enable_flag.: true |
| 50 | } |
| 51 | .build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/deref/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().; |
| 52 | |
| 53 | if field_attribute.flagrust-analyzer cargo educe 0.6.0 trait_handlers/deref/models/field_attribute/FieldAttribute#flag. { |
| 54 | if deref_field.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 55 | 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/deref/::panicrust-analyzer cargo educe 0.6.0 trait_handlers/deref/panic/::multiple_deref_fieldsrust-analyzer cargo educe 0.6.0 trait_handlers/deref/panic/multiple_deref_fields().( |
| 56 | field_attribute.spanrust-analyzer cargo educe 0.6.0 trait_handlers/deref/models/field_attribute/FieldAttribute#span., |
| 57 | )); |
| 58 | } |
| 59 | |
| 60 | deref_field = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((index, field)); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(deref_field) = deref_field { |
| 65 | deref_field |
| 66 | } else { |
| 67 | 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/deref/::panicrust-analyzer cargo educe 0.6.0 trait_handlers/deref/panic/::no_deref_fieldrust-analyzer cargo educe 0.6.0 trait_handlers/deref/panic/no_deref_field().(meta.spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().())); |
| 68 | } |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | let ty = &field.tyrust-analyzer cargo syn 2.0.119 data/Field#ty.; |
| 73 | let (dereference_ty, is_ref) = dereference_changedrust-analyzer cargo educe 0.6.0 common/`r#type`/dereference_changed().(ty); |
| 74 | |
| 75 | target_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!!(#dereference_ty)); |
| 76 | |
| 77 | 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().(), index); |
| 78 | |
| 79 | deref_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(if is_ref { |
| 80 | quoterust-analyzer cargo quote 1.0.47 quote!! (self.#field_name) |
| 81 | } else { |
| 82 | quoterust-analyzer cargo quote 1.0.47 quote!! (&self.#field_name) |
| 83 | }); |
| 84 | } |
| 85 | |
| 86 | let ident = &ast.identrust-analyzer cargo syn 2.0.119 derive/DeriveInput#ident.; |
| 87 | |
| 88 | let (impl_generics, ty_generics, where_clause) = ast.genericsrust-analyzer cargo syn 2.0.119 derive/DeriveInput#generics..split_for_implrust-analyzer cargo syn 2.0.119 generics/impl#[Generics]split_for_impl().(); |
| 89 | |
| 90 | token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 91 | impl #impl_generics ::core::ops::Deref for #ident #ty_generics #where_clause { |
| 92 | type Target = #target_token_stream; |
| 93 | |
| 94 | #[inline] |
| 95 | fn deref(&self) -> &Self::Target { |
| 96 | #deref_token_stream |
| 97 | } |
| 98 | } |
| 99 | }); |
| 100 | |
| 101 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 102 | } |
| 103 | } |