| 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/::{punctuatedrust-analyzer cargo syn 2.0.119 punctuated/::Punctuatedrust-analyzer cargo syn 2.0.119 punctuated/Punctuated#, 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#, Indexrust-analyzer cargo syn 2.0.119 expr/Index#, 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/clone/::modelsrust-analyzer cargo educe 0.6.0 trait_handlers/clone/models/::{FieldAttributerust-analyzer cargo educe 0.6.0 trait_handlers/clone/models/field_attribute/FieldAttribute#, FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/clone/models/field_attribute/FieldAttributeBuilder#, TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/clone/models/type_attribute/TypeAttributeBuilder#}; |
| 5 | use craterust-analyzer cargo educe 0.6.0 crate/::{ |
| 6 | commonrust-analyzer cargo educe 0.6.0 common/::where_predicates_boolrust-analyzer cargo educe 0.6.0 common/where_predicates_bool/::WherePredicatesrust-analyzer cargo educe 0.6.0 common/where_predicates_bool/WherePredicates#, supported_traitsrust-analyzer cargo educe 0.6.0 supported_traits/::Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#, TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler#, |
| 7 | }; |
| 8 | |
| 9 | pub(craterust-analyzer cargo educe 0.6.0 crate/) struct CloneStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/clone/clone_struct/CloneStructHandler#; |
| 10 | |
| 11 | impl TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler# for CloneStructHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/clone/clone_struct/CloneStructHandler# { |
| 12 | #[inline] |
| 13 | fn trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/clone/clone_struct/impl#[CloneStructHandler][TraitHandler]trait_meta_handler().( |
| 14 | ast: &DeriveInputrust-analyzer cargo syn 2.0.119 derive/DeriveInput#, |
| 15 | token_stream: &mut proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#, |
| 16 | traits: &[Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#], |
| 17 | meta: &Metarust-analyzer cargo syn 2.0.119 attr/Meta#, |
| 18 | ) -> synrust-analyzer cargo syn 2.0.119 crate/::Resultrust-analyzer cargo syn 2.0.119 error/Result#<()> { |
| 19 | let type_attribute = TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/clone/models/type_attribute/TypeAttributeBuilder# { |
| 20 | enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/clone/models/type_attribute/TypeAttributeBuilder#enable_flag.: true, enable_boundrust-analyzer cargo educe 0.6.0 trait_handlers/clone/models/type_attribute/TypeAttributeBuilder#enable_bound.: true |
| 21 | } |
| 22 | .build_from_clone_metarust-analyzer cargo educe 0.6.0 trait_handlers/clone/models/type_attribute/impl#[TypeAttributeBuilder]build_from_clone_meta().(meta)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 23 | |
| 24 | let mut bound: WherePredicatesrust-analyzer cargo educe 0.6.0 common/where_predicates_bool/WherePredicates# = Punctuatedrust-analyzer cargo syn 2.0.119 punctuated/Punctuated#::newrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Punctuated<T, P>`]new().(); |
| 25 | |
| 26 | let mut clone_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().(); |
| 27 | let mut clone_from_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().(); |
| 28 | |
| 29 | 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. { |
| 30 | let mut fields: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(&Fieldrust-analyzer cargo syn 2.0.119 data/Field#, FieldAttributerust-analyzer cargo educe 0.6.0 trait_handlers/clone/models/field_attribute/FieldAttribute#)> = 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 | #[cfg(feature = "Copy")] |
| 33 | let contains_copy = 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#::Copyrust-analyzer cargo educe 0.6.0 supported_traits/Trait#Copy#); |
| 34 | |
| 35 | #[cfg(not(feature = "Copy"))] |
| 36 | let contains_copy = false; |
| 37 | |
| 38 | if contains_copy { |
| 39 | clone_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!!(*self)); |
| 40 | } |
| 41 | |
| 42 | for field in data.fieldsrust-analyzer cargo syn 2.0.119 derive/DataStruct#fields..iterrust-analyzer cargo syn 2.0.119 data/impl#[Fields]iter().() { |
| 43 | let field_attribute = FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/clone/models/field_attribute/FieldAttributeBuilder# { |
| 44 | enable_methodrust-analyzer cargo educe 0.6.0 trait_handlers/clone/models/field_attribute/FieldAttributeBuilder#enable_method.: !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().contains_copy |
| 45 | } |
| 46 | .build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/clone/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().; |
| 47 | |
| 48 | fields.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((field, field_attribute)); |
| 49 | } |
| 50 | |
| 51 | let mut clone_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().(); |
| 52 | |
| 53 | match &data.fieldsrust-analyzer cargo syn 2.0.119 derive/DataStruct#fields. { |
| 54 | Fieldsrust-analyzer cargo syn 2.0.119 data/Fields#::Unitrust-analyzer cargo syn 2.0.119 data/Fields#Unit# => { |
| 55 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().contains_copy { |
| 56 | clone_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!!(Self)); |
| 57 | clone_from_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!!(let _ = source;)); |
| 58 | } |
| 59 | }, |
| 60 | Fieldsrust-analyzer cargo syn 2.0.119 data/Fields#::Namedrust-analyzer cargo syn 2.0.119 data/Fields#Named#(_) => { |
| 61 | let mut fields_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().(); |
| 62 | let mut clone_from_body_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().(); |
| 63 | |
| 64 | if fields.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 65 | clone_from_body_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!!(let _ = source;)); |
| 66 | } else { |
| 67 | for (field, field_attribute) in fields { |
| 68 | let field_name = 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().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 69 | |
| 70 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(clone) = field_attribute.methodrust-analyzer cargo educe 0.6.0 trait_handlers/clone/models/field_attribute/FieldAttribute#method..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() { |
| 71 | fields_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 72 | #field_name: #clone(&self.#field_name), |
| 73 | }); |
| 74 | |
| 75 | clone_from_body_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().( |
| 76 | quoterust-analyzer cargo quote 1.0.47 quote!!(self.#field_name = #clone(&source.#field_name);), |
| 77 | ); |
| 78 | } else { |
| 79 | clone_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.); |
| 80 | |
| 81 | fields_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 82 | #field_name: ::core::clone::Clone::clone(&self.#field_name), |
| 83 | }); |
| 84 | |
| 85 | clone_from_body_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().( |
| 86 | quoterust-analyzer cargo quote 1.0.47 quote!!( ::core::clone::Clone::clone_from(&mut self.#field_name, &source.#field_name); ), |
| 87 | ); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().contains_copy { |
| 93 | clone_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 94 | Self { |
| 95 | #fields_token_stream |
| 96 | } |
| 97 | }); |
| 98 | |
| 99 | clone_from_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(clone_from_body_token_stream); |
| 100 | } |
| 101 | }, |
| 102 | Fieldsrust-analyzer cargo syn 2.0.119 data/Fields#::Unnamedrust-analyzer cargo syn 2.0.119 data/Fields#Unnamed#(_) => { |
| 103 | let mut fields_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().(); |
| 104 | let mut clone_from_body_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().(); |
| 105 | |
| 106 | if fields.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 107 | clone_from_body_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!!(let _ = source;)); |
| 108 | } else { |
| 109 | for (index, (field, field_attribute)) in fields.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 110 | let field_name = Indexrust-analyzer cargo syn 2.0.119 expr/Index#::fromrust-analyzer cargo syn 2.0.119 expr/impl#[Index][`From<usize>`]from().(index); |
| 111 | |
| 112 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(clone) = field_attribute.methodrust-analyzer cargo educe 0.6.0 trait_handlers/clone/models/field_attribute/FieldAttribute#method..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() { |
| 113 | fields_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!!(#clone(&self.#field_name),)); |
| 114 | |
| 115 | clone_from_body_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.#field_name = #clone(&source.#field_name);), |
| 117 | ); |
| 118 | } else { |
| 119 | clone_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.); |
| 120 | |
| 121 | fields_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().( |
| 122 | quoterust-analyzer cargo quote 1.0.47 quote!! ( ::core::clone::Clone::clone(&self.#field_name), ), |
| 123 | ); |
| 124 | |
| 125 | clone_from_body_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().( |
| 126 | quoterust-analyzer cargo quote 1.0.47 quote!!( ::core::clone::Clone::clone_from(&mut self.#field_name, &source.#field_name); ), |
| 127 | ); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().contains_copy { |
| 133 | clone_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!!(Self ( #fields_token_stream ))); |
| 134 | clone_from_token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(clone_from_body_token_stream); |
| 135 | } |
| 136 | }, |
| 137 | } |
| 138 | |
| 139 | bound = type_attribute.boundrust-analyzer cargo educe 0.6.0 trait_handlers/clone/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().( |
| 140 | &ast.genericsrust-analyzer cargo syn 2.0.119 derive/DeriveInput#generics..paramsrust-analyzer cargo syn 2.0.119 generics/Generics#params., |
| 141 | &synrust-analyzer cargo syn 2.0.119 crate/::parse2rust-analyzer cargo syn 2.0.119 parse2().(if contains_copy { |
| 142 | quoterust-analyzer cargo quote 1.0.47 quote!!(::core::marker::Copy) |
| 143 | } else { |
| 144 | quoterust-analyzer cargo quote 1.0.47 quote!!(::core::clone::Clone) |
| 145 | }) |
| 146 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 147 | &clone_types, |
| 148 | &[], |
| 149 | ); |
| 150 | } |
| 151 | |
| 152 | let clone_from_fn_token_stream = if clone_from_token_stream.is_emptyrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream]is_empty().() { |
| 153 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 154 | } else { |
| 155 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 156 | #[inline] |
| 157 | fn clone_from(&mut self, source: &Self) { |
| 158 | #clone_from_token_stream |
| 159 | } |
| 160 | }) |
| 161 | }; |
| 162 | |
| 163 | let ident = &ast.identrust-analyzer cargo syn 2.0.119 derive/DeriveInput#ident.; |
| 164 | |
| 165 | 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().(); |
| 166 | let where_clause = generics.make_where_clauserust-analyzer cargo syn 2.0.119 generics/impl#[Generics]make_where_clause().(); |
| 167 | |
| 168 | for where_predicate in bound { |
| 169 | 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); |
| 170 | } |
| 171 | |
| 172 | let (impl_generics, ty_generics, where_clause) = generics.split_for_implrust-analyzer cargo syn 2.0.119 generics/impl#[Generics]split_for_impl().(); |
| 173 | |
| 174 | token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 175 | impl #impl_generics ::core::clone::Clone for #ident #ty_generics #where_clause { |
| 176 | #[inline] |
| 177 | fn clone(&self) -> Self { |
| 178 | #clone_token_stream |
| 179 | } |
| 180 | |
| 181 | #clone_from_fn_token_stream |
| 182 | } |
| 183 | }); |
| 184 | |
| 185 | #[cfg(feature = "Copy")] |
| 186 | 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#::Copyrust-analyzer cargo educe 0.6.0 supported_traits/Trait#Copy#) { |
| 187 | token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 188 | impl #impl_generics ::core::marker::Copy for #ident #ty_generics #where_clause { |
| 189 | } |
| 190 | }); |
| 191 | } |
| 192 | |
| 193 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 194 | } |
| 195 | } |