| 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#, Typerust-analyzer cargo syn 2.0.119 ty/Type#}; |
| 3 | |
| 4 | use superrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/::{ |
| 5 | modelsrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/::{FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/field_attribute/FieldAttributeBuilder#, TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/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 DerefMutStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/deref_mut_struct/DerefMutStructHandler#; |
| 11 | |
| 12 | impl TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler# for DerefMutStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/deref_mut_struct/DerefMutStructHandler# { |
| 13 | #[inline] |
| 14 | fn trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/deref_mut_struct/impl#[DerefMutStructHandler][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 _ = TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/type_attribute/TypeAttributeBuilder# { |
| 21 | enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/type_attribute/TypeAttributeBuilder#enable_flag.: true |
| 22 | } |
| 23 | .build_from_deref_mut_metarust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/type_attribute/impl#[TypeAttributeBuilder]build_from_deref_mut_meta().(meta)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 24 | |
| 25 | let mut deref_mut_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().(); |
| 26 | |
| 27 | 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. { |
| 28 | let (index, field) = { |
| 29 | let fields = &data.fieldsrust-analyzer cargo syn 2.0.119 derive/DataStruct#fields.; |
| 30 | |
| 31 | 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 { |
| 32 | 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().(); |
| 33 | |
| 34 | let _ = FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/field_attribute/FieldAttributeBuilder# { |
| 35 | enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/field_attribute/FieldAttributeBuilder#enable_flag.: true |
| 36 | } |
| 37 | .build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/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().; |
| 38 | |
| 39 | (0usize, field) |
| 40 | } else { |
| 41 | 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#; |
| 42 | |
| 43 | 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().() { |
| 44 | let field_attribute = FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/field_attribute/FieldAttributeBuilder# { |
| 45 | enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/field_attribute/FieldAttributeBuilder#enable_flag.: true |
| 46 | } |
| 47 | .build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/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().; |
| 48 | |
| 49 | if field_attribute.flagrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/field_attribute/FieldAttribute#flag. { |
| 50 | if deref_field.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 51 | 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_mut/::panicrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/panic/::multiple_deref_mut_fieldsrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/panic/multiple_deref_mut_fields().( |
| 52 | field_attribute.spanrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/field_attribute/FieldAttribute#span., |
| 53 | )); |
| 54 | } |
| 55 | |
| 56 | deref_field = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((index, field)); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(deref_field) = deref_field { |
| 61 | deref_field |
| 62 | } else { |
| 63 | 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_mut/::panicrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/panic/::no_deref_mut_fieldrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/panic/no_deref_mut_field().(meta.spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().())); |
| 64 | } |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | 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); |
| 69 | |
| 70 | deref_mut_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(if let Typerust-analyzer cargo syn 2.0.119 ty/Type#::Referencerust-analyzer cargo syn 2.0.119 ty/Type#Reference#(_) = &field.tyrust-analyzer cargo syn 2.0.119 data/Field#ty. { |
| 71 | quoterust-analyzer cargo quote 1.0.47 quote!! (self.#field_name) |
| 72 | } else { |
| 73 | quoterust-analyzer cargo quote 1.0.47 quote!! (&mut self.#field_name) |
| 74 | }); |
| 75 | } |
| 76 | |
| 77 | let ident = &ast.identrust-analyzer cargo syn 2.0.119 derive/DeriveInput#ident.; |
| 78 | |
| 79 | 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().(); |
| 80 | |
| 81 | token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 82 | impl #impl_generics ::core::ops::DerefMut for #ident #ty_generics #where_clause { |
| 83 | #[inline] |
| 84 | fn deref_mut(&mut self) -> &mut Self::Target { |
| 85 | #deref_mut_token_stream |
| 86 | } |
| 87 | } |
| 88 | }); |
| 89 | |
| 90 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 91 | } |
| 92 | } |