| 1 | use synrust-analyzer cargo syn 2.0.117 crate/::punctuatedrust-analyzer cargo syn 2.0.117 punctuated/::Punctuatedrust-analyzer cargo syn 2.0.117 punctuated/Punctuated#; |
| 2 | use synrust-analyzer cargo syn 2.0.117 crate/::{Attributerust-analyzer cargo syn 2.0.117 attr/Attribute#, Errorrust-analyzer cargo syn 2.0.117 error/Error#, Exprrust-analyzer cargo syn 2.0.117 expr/Expr#, ExprLitrust-analyzer cargo syn 2.0.117 expr/ExprLit#, Litrust-analyzer cargo syn 2.0.117 lit/Lit#, Metarust-analyzer cargo syn 2.0.117 attr/Meta#, Tokenrust-analyzer cargo syn 2.0.117 token/Token!}; |
| 3 | |
| 4 | use craterust-analyzer cargo postgres-derive 0.4.9 crate/::caserust-analyzer cargo postgres-derive 0.4.9 case/::{RENAME_RULESrust-analyzer cargo postgres-derive 0.4.9 case/RENAME_RULES., RenameRulerust-analyzer cargo postgres-derive 0.4.9 case/RenameRule#}; |
| 5 | |
| 6 | pub struct Overridesrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides# { |
| 7 | pub namerust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#name.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 8 | pub rename_allrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#rename_all.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<RenameRulerust-analyzer cargo postgres-derive 0.4.9 case/RenameRule#>, |
| 9 | pub transparentrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#transparent.: bool, |
| 10 | pub allow_mismatchrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#allow_mismatch.: bool, |
| 11 | } |
| 12 | |
| 13 | impl Overridesrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides# { |
| 14 | pub fn extractrust-analyzer cargo postgres-derive 0.4.9 overrides/impl#[Overrides]extract().(attrs: &[Attributerust-analyzer cargo syn 2.0.117 attr/Attribute#], container_attr: bool) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Overridesrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#, Errorrust-analyzer cargo syn 2.0.117 error/Error#> { |
| 15 | let mut overrides = Overridesrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides# { |
| 16 | namerust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#name.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 17 | rename_allrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#rename_all.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 18 | transparentrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#transparent.: false, |
| 19 | allow_mismatchrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#allow_mismatch.: false, |
| 20 | }; |
| 21 | |
| 22 | for attr in attrs { |
| 23 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().attr.pathrust-analyzer cargo syn 2.0.117 attr/impl#[Attribute]path().().is_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]is_ident().("postgres") { |
| 24 | continue; |
| 25 | } |
| 26 | |
| 27 | let list = match &attr.metarust-analyzer cargo syn 2.0.117 attr/Attribute#meta. { |
| 28 | Metarust-analyzer cargo syn 2.0.117 attr/Meta#::Listrust-analyzer cargo syn 2.0.117 attr/Meta#List#(list) => list, |
| 29 | bad => 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().(bad, "expected a #[postgres(...)]")), |
| 30 | }; |
| 31 | |
| 32 | let nested = list.parse_args_withrust-analyzer cargo syn 2.0.117 attr/impl#[MetaList]parse_args_with().(Punctuatedrust-analyzer cargo syn 2.0.117 punctuated/Punctuated#::<Metarust-analyzer cargo syn 2.0.117 attr/Meta#, Tokenrust-analyzer cargo syn 2.0.117 token/Token!![,]>::parse_terminatedrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]parse_terminated().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 33 | |
| 34 | for item in nested { |
| 35 | match item { |
| 36 | Metarust-analyzer cargo syn 2.0.117 attr/Meta#::NameValuerust-analyzer cargo syn 2.0.117 attr/Meta#NameValue#(meta) => { |
| 37 | let name_override = meta.pathrust-analyzer cargo syn 2.0.117 attr/MetaNameValue#path..is_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]is_ident().("name"); |
| 38 | let rename_all_override = meta.pathrust-analyzer cargo syn 2.0.117 attr/MetaNameValue#path..is_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]is_ident().("rename_all"); |
| 39 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().container_attr && rename_all_override { |
| 40 | 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().( |
| 41 | &meta.pathrust-analyzer cargo syn 2.0.117 attr/MetaNameValue#path., |
| 42 | "rename_all is a container attribute", |
| 43 | )); |
| 44 | } |
| 45 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().name_override && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().rename_all_override { |
| 46 | 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().(&meta.pathrust-analyzer cargo syn 2.0.117 attr/MetaNameValue#path., "unknown override")); |
| 47 | } |
| 48 | |
| 49 | let value = match &meta.valuerust-analyzer cargo syn 2.0.117 attr/MetaNameValue#value. { |
| 50 | Exprrust-analyzer cargo syn 2.0.117 expr/Expr#::Litrust-analyzer cargo syn 2.0.117 expr/Expr#Lit#(ExprLitrust-analyzer cargo syn 2.0.117 expr/ExprLit# { |
| 51 | litrust-analyzer cargo syn 2.0.117 expr/ExprLit#lit.: Litrust-analyzer cargo syn 2.0.117 lit/Lit#::Strrust-analyzer cargo syn 2.0.117 lit/Lit#Str#(lit), .. |
| 52 | }) => lit.valuerust-analyzer cargo syn 2.0.117 lit/impl#[LitStr]value().(), |
| 53 | bad => { |
| 54 | 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().(bad, "expected a string literal")); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | if name_override { |
| 59 | overrides.namerust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#name. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value); |
| 60 | } else if rename_all_override { |
| 61 | let rename_rule = RenameRulerust-analyzer cargo postgres-derive 0.4.9 case/RenameRule#::from_strrust-analyzer cargo postgres-derive 0.4.9 case/impl#[RenameRule]from_str().(&value).ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| { |
| 62 | Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().( |
| 63 | &meta.valuerust-analyzer cargo syn 2.0.117 attr/MetaNameValue#value., |
| 64 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 65 | "invalid rename_all rule, expected one of: {}", |
| 66 | RENAME_RULESrust-analyzer cargo postgres-derive 0.4.9 case/RENAME_RULES. |
| 67 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 68 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|rule| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("\"{rule}\"")) |
| 69 | .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#<_>>() |
| 70 | .joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().(", ") |
| 71 | ), |
| 72 | ) |
| 73 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 74 | |
| 75 | overrides.rename_allrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#rename_all. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(rename_rule); |
| 76 | } |
| 77 | } |
| 78 | Metarust-analyzer cargo syn 2.0.117 attr/Meta#::Pathrust-analyzer cargo syn 2.0.117 attr/Meta#Path#(path) => { |
| 79 | if path.is_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]is_ident().("transparent") { |
| 80 | if overrides.allow_mismatchrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#allow_mismatch. { |
| 81 | 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().( |
| 82 | path, |
| 83 | "#[postgres(allow_mismatch)] is not allowed with #[postgres(transparent)]", |
| 84 | )); |
| 85 | } |
| 86 | overrides.transparentrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#transparent. = true; |
| 87 | } else if path.is_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]is_ident().("allow_mismatch") { |
| 88 | if overrides.transparentrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#transparent. { |
| 89 | 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().( |
| 90 | path, |
| 91 | "#[postgres(transparent)] is not allowed with #[postgres(allow_mismatch)]", |
| 92 | )); |
| 93 | } |
| 94 | overrides.allow_mismatchrust-analyzer cargo postgres-derive 0.4.9 overrides/Overrides#allow_mismatch. = true; |
| 95 | } else { |
| 96 | 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().(path, "unknown override")); |
| 97 | } |
| 98 | } |
| 99 | bad => 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().(bad, "unknown attribute")), |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(overrides) |
| 105 | } |
| 106 | } |