| 1 | use quoterust-analyzer cargo quote 1.0.47 crate/::{format_identrust-analyzer cargo quote 1.0.47 format/format_ident!, 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#, Fieldsrust-analyzer cargo syn 2.0.119 data/Fields#, Identrust-analyzer cargo proc-macro2 1.0.107 Ident#, Metarust-analyzer cargo syn 2.0.119 attr/Meta#}; |
| 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/::{panicrust-analyzer cargo educe 0.6.0 panic/, supported_traitsrust-analyzer cargo educe 0.6.0 supported_traits/::Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#}; |
| 9 | |
| 10 | pub(craterust-analyzer cargo educe 0.6.0 crate/) struct DerefMutEnumHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/deref_mut_enum/DerefMutEnumHandler#; |
| 11 | |
| 12 | impl TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler# for DerefMutEnumHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/deref_mut_enum/DerefMutEnumHandler# { |
| 13 | #[inline] |
| 14 | fn trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/deref_mut_enum/impl#[DerefMutEnumHandler][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 arms_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#::Enumrust-analyzer cargo syn 2.0.119 derive/Data#Enum#(data) = &ast.datarust-analyzer cargo syn 2.0.119 derive/DeriveInput#data. { |
| 28 | type Variantsrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/deref_mut_enum/Variants#<'a> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(&'a Identrust-analyzer cargo proc-macro2 1.0.107 Ident#, bool, usize, Identrust-analyzer cargo proc-macro2 1.0.107 Ident#)>; |
| 29 | |
| 30 | let mut variants: Variantsrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/deref_mut_enum/Variants# = 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().(); |
| 31 | |
| 32 | for variant in data.variantsrust-analyzer cargo syn 2.0.119 derive/DataEnum#variants..iterrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Punctuated<T, P>`]iter().() { |
| 33 | let _ = TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/type_attribute/TypeAttributeBuilder# { |
| 34 | enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/type_attribute/TypeAttributeBuilder#enable_flag.: false |
| 35 | } |
| 36 | .build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/type_attribute/impl#[TypeAttributeBuilder]build_from_attributes().(&variant.attrsrust-analyzer cargo syn 2.0.119 data/Variant#attrs., traits)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 37 | |
| 38 | if let Fieldsrust-analyzer cargo syn 2.0.119 data/Fields#::Unitrust-analyzer cargo syn 2.0.119 data/Fields#Unit# = &variant.fieldsrust-analyzer cargo syn 2.0.119 data/Variant#fields. { |
| 39 | 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_support_unit_variantrust-analyzer cargo educe 0.6.0 panic/trait_not_support_unit_variant().( |
| 40 | 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().(), |
| 41 | variant, |
| 42 | )); |
| 43 | } |
| 44 | |
| 45 | let fields = &variant.fieldsrust-analyzer cargo syn 2.0.119 data/Variant#fields.; |
| 46 | |
| 47 | let (index, field) = 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 { |
| 48 | 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().(); |
| 49 | |
| 50 | let _ = FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/field_attribute/FieldAttributeBuilder# { |
| 51 | enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/field_attribute/FieldAttributeBuilder#enable_flag.: true |
| 52 | } |
| 53 | .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().; |
| 54 | |
| 55 | (0usize, field) |
| 56 | } else { |
| 57 | 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#; |
| 58 | |
| 59 | for (index, field) in variant.fieldsrust-analyzer cargo syn 2.0.119 data/Variant#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().() { |
| 60 | let field_attribute = FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/field_attribute/FieldAttributeBuilder# { |
| 61 | enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/field_attribute/FieldAttributeBuilder#enable_flag.: true |
| 62 | } |
| 63 | .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().; |
| 64 | |
| 65 | if field_attribute.flagrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/field_attribute/FieldAttribute#flag. { |
| 66 | if deref_field.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 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_mut/::panicrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/panic/::multiple_deref_mut_fields_of_variantrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/panic/multiple_deref_mut_fields_of_variant().( |
| 68 | field_attribute.spanrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/models/field_attribute/FieldAttribute#span., |
| 69 | variant, |
| 70 | )); |
| 71 | } |
| 72 | |
| 73 | deref_field = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((index, field)); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(deref_field) = deref_field { |
| 78 | deref_field |
| 79 | } else { |
| 80 | 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_field_of_variantrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/panic/no_deref_mut_field_of_variant().( |
| 81 | meta.spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), |
| 82 | variant, |
| 83 | )); |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | let (field_name, is_tuple): (Identrust-analyzer cargo proc-macro2 1.0.107 Ident#, bool) = match 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().() { |
| 88 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ident) => (ident.clonerust-analyzer cargo proc-macro2 1.0.107 impl#[Ident][Clone]clone().(), false), |
| 89 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => (format_identrust-analyzer cargo quote 1.0.47 format/format_ident!!("_{}", index), true), |
| 90 | }; |
| 91 | |
| 92 | variants.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((&variant.identrust-analyzer cargo syn 2.0.119 data/Variant#ident., is_tuple, index, field_name)); |
| 93 | } |
| 94 | |
| 95 | if variants.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 96 | 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().())); |
| 97 | } |
| 98 | |
| 99 | for (variant_ident, is_tuple, index, field_name) in variants { |
| 100 | let mut pattern_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().(); |
| 101 | |
| 102 | if is_tuple { |
| 103 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#index { |
| 104 | pattern_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!!(_,)); |
| 105 | } |
| 106 | |
| 107 | pattern_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!!( #field_name, .. )); |
| 108 | |
| 109 | arms_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().( |
| 110 | quoterust-analyzer cargo quote 1.0.47 quote!!( Self::#variant_ident ( #pattern_token_stream ) => #field_name, ), |
| 111 | ); |
| 112 | } else { |
| 113 | pattern_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!!( #field_name, .. )); |
| 114 | |
| 115 | arms_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().( |
| 116 | quoterust-analyzer cargo quote 1.0.47 quote!!( Self::#variant_ident { #pattern_token_stream } => #field_name, ), |
| 117 | ); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | let ident = &ast.identrust-analyzer cargo syn 2.0.119 derive/DeriveInput#ident.; |
| 123 | |
| 124 | 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().(); |
| 125 | |
| 126 | token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 127 | impl #impl_generics ::core::ops::DerefMut for #ident #ty_generics #where_clause { |
| 128 | #[inline] |
| 129 | fn deref_mut(&mut self) -> &mut Self::Target { |
| 130 | match self { |
| 131 | #arms_token_stream |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | }); |
| 136 | |
| 137 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 138 | } |
| 139 | } |