| 1 | use proc_macro2rust-analyzer cargo proc-macro2 1.0.106 crate/::{Spanrust-analyzer cargo proc-macro2 1.0.106 Span#, TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#}; |
| 2 | use quoterust-analyzer cargo quote 1.0.45 crate/::{format_identrust-analyzer cargo quote 1.0.45 format/format_ident!, quoterust-analyzer cargo quote 1.0.45 quote!}; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/; |
| 4 | use synrust-analyzer cargo syn 2.0.117 crate/::{ |
| 5 | AngleBracketedGenericArgumentsrust-analyzer cargo syn 2.0.117 path/AngleBracketedGenericArguments#, Datarust-analyzer cargo syn 2.0.117 derive/Data#, DataStructrust-analyzer cargo syn 2.0.117 derive/DataStruct#, DeriveInputrust-analyzer cargo syn 2.0.117 derive/DeriveInput#, Errorrust-analyzer cargo syn 2.0.117 error/Error#, Fieldsrust-analyzer cargo syn 2.0.117 data/Fields#, GenericArgumentrust-analyzer cargo syn 2.0.117 path/GenericArgument#, |
| 6 | GenericParamrust-analyzer cargo syn 2.0.117 generics/GenericParam#, Genericsrust-analyzer cargo syn 2.0.117 generics/Generics#, Identrust-analyzer cargo proc-macro2 1.0.106 Ident#, Lifetimerust-analyzer cargo syn 2.0.117 lifetime/Lifetime#, PathArgumentsrust-analyzer cargo syn 2.0.117 path/PathArguments#, PathSegmentrust-analyzer cargo syn 2.0.117 path/PathSegment#, punctuatedrust-analyzer cargo syn 2.0.117 punctuated/::Punctuatedrust-analyzer cargo syn 2.0.117 punctuated/Punctuated#, |
| 7 | tokenrust-analyzer cargo syn 2.0.117 token/, |
| 8 | }; |
| 9 | use synrust-analyzer cargo syn 2.0.117 crate/::{LifetimeParamrust-analyzer cargo syn 2.0.117 generics/LifetimeParam#, TraitBoundrust-analyzer cargo syn 2.0.117 generics/TraitBound#, TraitBoundModifierrust-analyzer cargo syn 2.0.117 generics/TraitBoundModifier#, TypeParamBoundrust-analyzer cargo syn 2.0.117 generics/TypeParamBound#}; |
| 10 | |
| 11 | use craterust-analyzer cargo postgres-derive 0.4.9 crate/::acceptsrust-analyzer cargo postgres-derive 0.4.9 accepts/; |
| 12 | use craterust-analyzer cargo postgres-derive 0.4.9 crate/::compositesrust-analyzer cargo postgres-derive 0.4.9 composites/::Fieldrust-analyzer cargo postgres-derive 0.4.9 composites/Field#; |
| 13 | use craterust-analyzer cargo postgres-derive 0.4.9 crate/::compositesrust-analyzer cargo postgres-derive 0.4.9 composites/::{append_generic_boundrust-analyzer cargo postgres-derive 0.4.9 composites/append_generic_bound()., new_derive_pathrust-analyzer cargo postgres-derive 0.4.9 composites/new_derive_path().}; |
| 14 | use craterust-analyzer cargo postgres-derive 0.4.9 crate/::enumsrust-analyzer cargo postgres-derive 0.4.9 enums/::Variantrust-analyzer cargo postgres-derive 0.4.9 enums/Variant#; |
| 15 | use craterust-analyzer cargo postgres-derive 0.4.9 crate/::overridesrust-analyzer cargo postgres-derive 0.4.9 overrides/::Overridesrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#; |
| 16 | |
| 17 | pub fn expand_derive_fromsqlrust-analyzer cargo postgres-derive 0.4.9 fromsql/expand_derive_fromsql().(input: DeriveInputrust-analyzer cargo syn 2.0.117 derive/DeriveInput#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#, Errorrust-analyzer cargo syn 2.0.117 error/Error#> { |
| 18 | let overrides = Overridesrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#::extractrust-analyzer cargo postgres-derive 0.4.9 overrides/impl#[Overrides]extract().(&input.attrsrust-analyzer cargo syn 2.0.117 derive/DeriveInput#attrs., true)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 19 | |
| 20 | if (overrides.namerust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#name..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() || overrides.rename_allrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#rename_all..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()) && overrides.transparentrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#transparent. { |
| 21 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().( |
| 22 | &input, |
| 23 | "#[postgres(transparent)] is not allowed with #[postgres(name = \"...\")] or #[postgres(rename_all = \"...\")]", |
| 24 | )); |
| 25 | } |
| 26 | |
| 27 | let name = overrides |
| 28 | .namerust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#name. |
| 29 | .clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().() |
| 30 | .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| input.identrust-analyzer cargo syn 2.0.117 derive/DeriveInput#ident..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 31 | |
| 32 | let (accepts_body, to_sql_body) = if overrides.transparentrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#transparent. { |
| 33 | match input.datarust-analyzer cargo syn 2.0.117 derive/DeriveInput#data. { |
| 34 | Datarust-analyzer cargo syn 2.0.117 derive/Data#::Structrust-analyzer cargo syn 2.0.117 derive/Data#Struct#(DataStructrust-analyzer cargo syn 2.0.117 derive/DataStruct# { |
| 35 | fieldsrust-analyzer cargo syn 2.0.117 derive/DataStruct#fields.: Fieldsrust-analyzer cargo syn 2.0.117 data/Fields#::Unnamedrust-analyzer cargo syn 2.0.117 data/Fields#Unnamed#(ref fields), |
| 36 | .. |
| 37 | }) if fields.unnamedrust-analyzer cargo syn 2.0.117 data/FieldsUnnamed#unnamed..lenrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]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 => { |
| 38 | let field = fields.unnamedrust-analyzer cargo syn 2.0.117 data/FieldsUnnamed#unnamed..firstrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]first().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 39 | ( |
| 40 | acceptsrust-analyzer cargo postgres-derive 0.4.9 accepts/::transparent_bodyrust-analyzer cargo postgres-derive 0.4.9 accepts/transparent_body().(field), |
| 41 | transparent_bodyrust-analyzer cargo postgres-derive 0.4.9 fromsql/transparent_body().(&input.identrust-analyzer cargo syn 2.0.117 derive/DeriveInput#ident., field), |
| 42 | ) |
| 43 | } |
| 44 | _ => { |
| 45 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().( |
| 46 | input, |
| 47 | "#[postgres(transparent)] may only be applied to single field tuple structs", |
| 48 | )); |
| 49 | } |
| 50 | } |
| 51 | } else if overrides.allow_mismatchrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#allow_mismatch. { |
| 52 | match input.datarust-analyzer cargo syn 2.0.117 derive/DeriveInput#data. { |
| 53 | Datarust-analyzer cargo syn 2.0.117 derive/Data#::Enumrust-analyzer cargo syn 2.0.117 derive/Data#Enum#(ref data) => { |
| 54 | let variants = data |
| 55 | .variantsrust-analyzer cargo syn 2.0.117 derive/DataEnum#variants. |
| 56 | .iterrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]iter().() |
| 57 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|variant| Variantrust-analyzer cargo postgres-derive 0.4.9 enums/Variant#::parserust-analyzer cargo postgres-derive 0.4.9 enums/impl#[Variant]parse().(variant, overrides.rename_allrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#rename_all.)) |
| 58 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>, _>>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 59 | ( |
| 60 | acceptsrust-analyzer cargo postgres-derive 0.4.9 accepts/::enum_bodyrust-analyzer cargo postgres-derive 0.4.9 accepts/enum_body().(&name, &variants, overrides.allow_mismatchrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#allow_mismatch.), |
| 61 | enum_bodyrust-analyzer cargo postgres-derive 0.4.9 fromsql/enum_body().(&input.identrust-analyzer cargo syn 2.0.117 derive/DeriveInput#ident., &variants), |
| 62 | ) |
| 63 | } |
| 64 | _ => { |
| 65 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().( |
| 66 | input, |
| 67 | "#[postgres(allow_mismatch)] may only be applied to enums", |
| 68 | )); |
| 69 | } |
| 70 | } |
| 71 | } else { |
| 72 | match input.datarust-analyzer cargo syn 2.0.117 derive/DeriveInput#data. { |
| 73 | Datarust-analyzer cargo syn 2.0.117 derive/Data#::Enumrust-analyzer cargo syn 2.0.117 derive/Data#Enum#(ref data) => { |
| 74 | let variants = data |
| 75 | .variantsrust-analyzer cargo syn 2.0.117 derive/DataEnum#variants. |
| 76 | .iterrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]iter().() |
| 77 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|variant| Variantrust-analyzer cargo postgres-derive 0.4.9 enums/Variant#::parserust-analyzer cargo postgres-derive 0.4.9 enums/impl#[Variant]parse().(variant, overrides.rename_allrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#rename_all.)) |
| 78 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>, _>>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 79 | ( |
| 80 | acceptsrust-analyzer cargo postgres-derive 0.4.9 accepts/::enum_bodyrust-analyzer cargo postgres-derive 0.4.9 accepts/enum_body().(&name, &variants, overrides.allow_mismatchrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#allow_mismatch.), |
| 81 | enum_bodyrust-analyzer cargo postgres-derive 0.4.9 fromsql/enum_body().(&input.identrust-analyzer cargo syn 2.0.117 derive/DeriveInput#ident., &variants), |
| 82 | ) |
| 83 | } |
| 84 | Datarust-analyzer cargo syn 2.0.117 derive/Data#::Structrust-analyzer cargo syn 2.0.117 derive/Data#Struct#(DataStructrust-analyzer cargo syn 2.0.117 derive/DataStruct# { |
| 85 | fieldsrust-analyzer cargo syn 2.0.117 derive/DataStruct#fields.: Fieldsrust-analyzer cargo syn 2.0.117 data/Fields#::Unnamedrust-analyzer cargo syn 2.0.117 data/Fields#Unnamed#(ref fields), |
| 86 | .. |
| 87 | }) if fields.unnamedrust-analyzer cargo syn 2.0.117 data/FieldsUnnamed#unnamed..lenrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]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 => { |
| 88 | let field = fields.unnamedrust-analyzer cargo syn 2.0.117 data/FieldsUnnamed#unnamed..firstrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]first().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 89 | ( |
| 90 | domain_accepts_bodyrust-analyzer cargo postgres-derive 0.4.9 fromsql/domain_accepts_body().(&name, field), |
| 91 | domain_bodyrust-analyzer cargo postgres-derive 0.4.9 fromsql/domain_body().(&input.identrust-analyzer cargo syn 2.0.117 derive/DeriveInput#ident., field), |
| 92 | ) |
| 93 | } |
| 94 | Datarust-analyzer cargo syn 2.0.117 derive/Data#::Structrust-analyzer cargo syn 2.0.117 derive/Data#Struct#(DataStructrust-analyzer cargo syn 2.0.117 derive/DataStruct# { |
| 95 | fieldsrust-analyzer cargo syn 2.0.117 derive/DataStruct#fields.: Fieldsrust-analyzer cargo syn 2.0.117 data/Fields#::Namedrust-analyzer cargo syn 2.0.117 data/Fields#Named#(ref fields), |
| 96 | .. |
| 97 | }) => { |
| 98 | let fields = fields |
| 99 | .namedrust-analyzer cargo syn 2.0.117 data/FieldsNamed#named. |
| 100 | .iterrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]iter().() |
| 101 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|field| Fieldrust-analyzer cargo postgres-derive 0.4.9 composites/Field#::parserust-analyzer cargo postgres-derive 0.4.9 composites/impl#[Field]parse().(field, overrides.rename_allrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#rename_all.)) |
| 102 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>, _>>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 103 | ( |
| 104 | acceptsrust-analyzer cargo postgres-derive 0.4.9 accepts/::composite_bodyrust-analyzer cargo postgres-derive 0.4.9 accepts/composite_body().(&name, "FromSql", &fields), |
| 105 | composite_bodyrust-analyzer cargo postgres-derive 0.4.9 fromsql/composite_body().(&input.identrust-analyzer cargo syn 2.0.117 derive/DeriveInput#ident., &fields), |
| 106 | ) |
| 107 | } |
| 108 | _ => { |
| 109 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().( |
| 110 | input, |
| 111 | "#[derive(FromSql)] may only be applied to structs, single field tuple structs, and enums", |
| 112 | )); |
| 113 | } |
| 114 | } |
| 115 | }; |
| 116 | |
| 117 | let ident = &input.identrust-analyzer cargo syn 2.0.117 derive/DeriveInput#ident.; |
| 118 | let (generics, lifetime) = build_genericsrust-analyzer cargo postgres-derive 0.4.9 fromsql/build_generics().(&input.genericsrust-analyzer cargo syn 2.0.117 derive/DeriveInput#generics.); |
| 119 | let (impl_generics, _, _) = generics.split_for_implrust-analyzer cargo syn 2.0.117 generics/impl#[Generics]split_for_impl().(); |
| 120 | let (_, ty_generics, where_clause) = input.genericsrust-analyzer cargo syn 2.0.117 derive/DeriveInput#generics..split_for_implrust-analyzer cargo syn 2.0.117 generics/impl#[Generics]split_for_impl().(); |
| 121 | let out = quoterust-analyzer cargo quote 1.0.45 quote!! { |
| 122 | impl #impl_generics postgres_types::FromSql<#lifetime> for #ident #ty_generics #where_clause { |
| 123 | fn from_sql(_type: &postgres_types::Type, buf: &#lifetime [u8]) |
| 124 | -> std::result::Result<#ident #ty_generics, |
| 125 | std::boxed::Box<dyn std::error::Error + |
| 126 | std::marker::Sync + |
| 127 | std::marker::Send>> { |
| 128 | #to_sql_body |
| 129 | } |
| 130 | |
| 131 | fn accepts(type_: &postgres_types::Type) -> bool { |
| 132 | #accepts_body |
| 133 | } |
| 134 | } |
| 135 | }; |
| 136 | |
| 137 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(out) |
| 138 | } |
| 139 | |
| 140 | fn transparent_bodyrust-analyzer cargo postgres-derive 0.4.9 fromsql/transparent_body().(ident: &Identrust-analyzer cargo proc-macro2 1.0.106 Ident#, field: &synrust-analyzer cargo syn 2.0.117 crate/::Fieldrust-analyzer cargo syn 2.0.117 data/Field#) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# { |
| 141 | let ty = &field.tyrust-analyzer cargo syn 2.0.117 data/Field#ty.; |
| 142 | quoterust-analyzer cargo quote 1.0.45 quote!! { |
| 143 | <#ty as postgres_types::FromSql>::from_sql(_type, buf).map(#ident) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | fn enum_bodyrust-analyzer cargo postgres-derive 0.4.9 fromsql/enum_body().(ident: &Identrust-analyzer cargo proc-macro2 1.0.106 Ident#, variants: &[Variantrust-analyzer cargo postgres-derive 0.4.9 enums/Variant#]) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# { |
| 148 | let variant_names = variants.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|v| &v.namerust-analyzer cargo postgres-derive 0.4.9 enums/Variant#name.); |
| 149 | let idents = iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::repeatrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/repeat/repeat().(ident); |
| 150 | let variant_idents = variants.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|v| &v.identrust-analyzer cargo postgres-derive 0.4.9 enums/Variant#ident.); |
| 151 | |
| 152 | quoterust-analyzer cargo quote 1.0.45 quote!! { |
| 153 | match std::str::from_utf8(buf)? { |
| 154 | #( |
| 155 | #variant_names => std::result::Result::Ok(#idents::#variant_idents), |
| 156 | )* |
| 157 | s => { |
| 158 | std::result::Result::Err( |
| 159 | std::convert::Into::into(format!("invalid variant `{}`", s))) |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // Domains are sometimes but not always just represented by the bare type (!?) |
| 166 | fn domain_accepts_bodyrust-analyzer cargo postgres-derive 0.4.9 fromsql/domain_accepts_body().(name: &str, field: &synrust-analyzer cargo syn 2.0.117 crate/::Fieldrust-analyzer cargo syn 2.0.117 data/Field#) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# { |
| 167 | let ty = &field.tyrust-analyzer cargo syn 2.0.117 data/Field#ty.; |
| 168 | let normal_body = acceptsrust-analyzer cargo postgres-derive 0.4.9 accepts/::domain_bodyrust-analyzer cargo postgres-derive 0.4.9 accepts/domain_body().(name, field); |
| 169 | |
| 170 | quoterust-analyzer cargo quote 1.0.45 quote!! { |
| 171 | if <#ty as postgres_types::FromSql>::accepts(type_) { |
| 172 | return true; |
| 173 | } |
| 174 | |
| 175 | #normal_body |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | fn domain_bodyrust-analyzer cargo postgres-derive 0.4.9 fromsql/domain_body().(ident: &Identrust-analyzer cargo proc-macro2 1.0.106 Ident#, field: &synrust-analyzer cargo syn 2.0.117 crate/::Fieldrust-analyzer cargo syn 2.0.117 data/Field#) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# { |
| 180 | let ty = &field.tyrust-analyzer cargo syn 2.0.117 data/Field#ty.; |
| 181 | quoterust-analyzer cargo quote 1.0.45 quote!! { |
| 182 | <#ty as postgres_types::FromSql>::from_sql(match *_type.kind() { |
| 183 | postgres_types::Kind::Domain(ref _type) => _type, |
| 184 | _ => _type |
| 185 | }, buf).map(#ident) |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | fn composite_bodyrust-analyzer cargo postgres-derive 0.4.9 fromsql/composite_body().(ident: &Identrust-analyzer cargo proc-macro2 1.0.106 Ident#, fields: &[Fieldrust-analyzer cargo postgres-derive 0.4.9 composites/Field#]) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# { |
| 190 | let temp_vars = &fields |
| 191 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 192 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|f| format_identrust-analyzer cargo quote 1.0.45 format/format_ident!!("__{}", f.identrust-analyzer cargo postgres-derive 0.4.9 composites/Field#ident.)) |
| 193 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 194 | let field_names = &fields.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|f| &f.namerust-analyzer cargo postgres-derive 0.4.9 composites/Field#name.).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 195 | let field_idents = &fields.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|f| &f.identrust-analyzer cargo postgres-derive 0.4.9 composites/Field#ident.).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 196 | |
| 197 | quoterust-analyzer cargo quote 1.0.45 quote!! { |
| 198 | let fields = match *_type.kind() { |
| 199 | postgres_types::Kind::Composite(ref fields) => fields, |
| 200 | _ => unreachable!(), |
| 201 | }; |
| 202 | |
| 203 | let mut buf = buf; |
| 204 | let num_fields = postgres_types::private::read_be_i32(&mut buf)?; |
| 205 | if num_fields as usize != fields.len() { |
| 206 | return std::result::Result::Err( |
| 207 | std::convert::Into::into(format!("invalid field count: {} vs {}", num_fields, fields.len()))); |
| 208 | } |
| 209 | |
| 210 | #( |
| 211 | let mut #temp_vars = std::option::Option::None; |
| 212 | )* |
| 213 | |
| 214 | for field in fields { |
| 215 | let oid = postgres_types::private::read_be_i32(&mut buf)? as u32; |
| 216 | if oid != field.type_().oid() { |
| 217 | return std::result::Result::Err(std::convert::Into::into("unexpected OID")); |
| 218 | } |
| 219 | |
| 220 | match field.name() { |
| 221 | #( |
| 222 | #field_names => { |
| 223 | #temp_vars = std::option::Option::Some( |
| 224 | postgres_types::private::read_value(field.type_(), &mut buf)?); |
| 225 | } |
| 226 | )* |
| 227 | _ => unreachable!(), |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | std::result::Result::Ok(#ident { |
| 232 | #( |
| 233 | // A field is left unset if the server's composite type omitted it |
| 234 | // (e.g. reported a duplicate field name); error rather than panic. |
| 235 | #field_idents: #temp_vars.ok_or("composite type is missing a field")?, |
| 236 | )* |
| 237 | }) |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | fn build_genericsrust-analyzer cargo postgres-derive 0.4.9 fromsql/build_generics().(source: &Genericsrust-analyzer cargo syn 2.0.117 generics/Generics#) -> (Genericsrust-analyzer cargo syn 2.0.117 generics/Generics#, Lifetimerust-analyzer cargo syn 2.0.117 lifetime/Lifetime#) { |
| 242 | // don't worry about lifetime name collisions, it doesn't make sense to derive FromSql on a struct with a lifetime |
| 243 | let lifetime = Lifetimerust-analyzer cargo syn 2.0.117 lifetime/Lifetime#::newrust-analyzer cargo syn 2.0.117 lifetime/impl#[Lifetime]new().("'a", Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().()); |
| 244 | |
| 245 | let mut out = append_generic_boundrust-analyzer cargo postgres-derive 0.4.9 composites/append_generic_bound().(source.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().(), &new_fromsql_boundrust-analyzer cargo postgres-derive 0.4.9 fromsql/new_fromsql_bound().(&lifetime)); |
| 246 | out.paramsrust-analyzer cargo syn 2.0.117 generics/Generics#params..insertrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]insert().( |
| 247 | 0, |
| 248 | GenericParamrust-analyzer cargo syn 2.0.117 generics/GenericParam#::Lifetimerust-analyzer cargo syn 2.0.117 generics/GenericParam#Lifetime#(LifetimeParamrust-analyzer cargo syn 2.0.117 generics/LifetimeParam#::newrust-analyzer cargo syn 2.0.117 generics/impl#[LifetimeParam]new().(lifetime.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().())), |
| 249 | ); |
| 250 | |
| 251 | (out, lifetime) |
| 252 | } |
| 253 | |
| 254 | fn new_fromsql_boundrust-analyzer cargo postgres-derive 0.4.9 fromsql/new_fromsql_bound().(lifetime: &Lifetimerust-analyzer cargo syn 2.0.117 lifetime/Lifetime#) -> TypeParamBoundrust-analyzer cargo syn 2.0.117 generics/TypeParamBound# { |
| 255 | let mut path_segment: PathSegmentrust-analyzer cargo syn 2.0.117 path/PathSegment# = Identrust-analyzer cargo proc-macro2 1.0.106 Ident#::newrust-analyzer cargo proc-macro2 1.0.106 impl#[Ident]new().("FromSql", Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().()).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 256 | let mut seg_args = Punctuatedrust-analyzer cargo syn 2.0.117 punctuated/Punctuated#::newrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]new().(); |
| 257 | seg_args.pushrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]push().(GenericArgumentrust-analyzer cargo syn 2.0.117 path/GenericArgument#::Lifetimerust-analyzer cargo syn 2.0.117 path/GenericArgument#Lifetime#(lifetime.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().())); |
| 258 | path_segment.argumentsrust-analyzer cargo syn 2.0.117 path/PathSegment#arguments. = PathArgumentsrust-analyzer cargo syn 2.0.117 path/PathArguments#::AngleBracketedrust-analyzer cargo syn 2.0.117 path/PathArguments#AngleBracketed#(AngleBracketedGenericArgumentsrust-analyzer cargo syn 2.0.117 path/AngleBracketedGenericArguments# { |
| 259 | colon2_tokenrust-analyzer cargo syn 2.0.117 path/AngleBracketedGenericArguments#colon2_token.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 260 | lt_tokenrust-analyzer cargo syn 2.0.117 path/AngleBracketedGenericArguments#lt_token.: tokenrust-analyzer cargo syn 2.0.117 token/::Ltrust-analyzer cargo syn 2.0.117 token/Lt#::defaultrust-analyzer cargo syn 2.0.117 token/impl#[Lt][Default]default().(), |
| 261 | argsrust-analyzer cargo syn 2.0.117 path/AngleBracketedGenericArguments#args.: seg_args, |
| 262 | gt_tokenrust-analyzer cargo syn 2.0.117 path/AngleBracketedGenericArguments#gt_token.: tokenrust-analyzer cargo syn 2.0.117 token/::Gtrust-analyzer cargo syn 2.0.117 token/Gt#::defaultrust-analyzer cargo syn 2.0.117 token/impl#[Gt][Default]default().(), |
| 263 | }); |
| 264 | |
| 265 | TypeParamBoundrust-analyzer cargo syn 2.0.117 generics/TypeParamBound#::Traitrust-analyzer cargo syn 2.0.117 generics/TypeParamBound#Trait#(TraitBoundrust-analyzer cargo syn 2.0.117 generics/TraitBound# { |
| 266 | lifetimesrust-analyzer cargo syn 2.0.117 generics/TraitBound#lifetimes.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 267 | modifierrust-analyzer cargo syn 2.0.117 generics/TraitBound#modifier.: TraitBoundModifierrust-analyzer cargo syn 2.0.117 generics/TraitBoundModifier#::Nonerust-analyzer cargo syn 2.0.117 generics/TraitBoundModifier#None#, |
| 268 | paren_tokenrust-analyzer cargo syn 2.0.117 generics/TraitBound#paren_token.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 269 | pathrust-analyzer cargo syn 2.0.117 generics/TraitBound#path.: new_derive_pathrust-analyzer cargo postgres-derive 0.4.9 composites/new_derive_path().(path_segment), |
| 270 | }) |
| 271 | } |