Debian Codegraph @

src/accepts.rs

raw symbols SCIP
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/::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/::Identrust-analyzer cargo proc-macro2 1.0.106 Ident#;
5
6 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#;
7 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#;
8
9 pub fn transparent_bodyrust-analyzer cargo postgres-derive 0.4.9 accepts/transparent_body().(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# {
10 let ty = &field.tyrust-analyzer cargo syn 2.0.117 data/Field#ty.;
11
12 quoterust-analyzer cargo quote 1.0.45 quote!! {
13 <#ty as ::postgres_types::ToSql>::accepts(type_)
14 }
15 }
16
17 pub fn domain_bodyrust-analyzer cargo postgres-derive 0.4.9 accepts/domain_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# {
18 let ty = &field.tyrust-analyzer cargo syn 2.0.117 data/Field#ty.;
19
20 quoterust-analyzer cargo quote 1.0.45 quote!! {
21 if type_.name() != #name {
22 return false;
23 }
24
25 match *type_.kind() {
26 ::postgres_types::Kind::Domain(ref type_) => {
27 <#ty as ::postgres_types::ToSql>::accepts(type_)
28 }
29 _ => false,
30 }
31 }
32 }
33
34 pub fn enum_bodyrust-analyzer cargo postgres-derive 0.4.9 accepts/enum_body().(name: &str, variants: &[Variantrust-analyzer cargo postgres-derive 0.4.9 enums/Variant#], allow_mismatch: bool) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# {
35 let num_variants = variants.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
36 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.);
37
38 if allow_mismatch {
39 quoterust-analyzer cargo quote 1.0.45 quote!! {
40 type_.name() == #name
41 }
42 } else {
43 quoterust-analyzer cargo quote 1.0.45 quote!! {
44 if type_.name() != #name {
45 return false;
46 }
47
48 match *type_.kind() {
49 ::postgres_types::Kind::Enum(ref variants) => {
50 if variants.len() != #num_variants {
51 return false;
52 }
53
54 variants.iter().all(|v| {
55 match &**v {
56 #(
57 #variant_names => true,
58 )*
59 _ => false,
60 }
61 })
62 }
63 _ => false,
64 }
65 }
66 }
67 }
68
69 pub fn composite_bodyrust-analyzer cargo postgres-derive 0.4.9 accepts/composite_body().(name: &str, trait_: &str, fields: &[Fieldrust-analyzer cargo postgres-derive 0.4.9 composites/Field#]) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# {
70 let num_fields = fields.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
71 let trait_ = Identrust-analyzer cargo proc-macro2 1.0.106 Ident#::newrust-analyzer cargo proc-macro2 1.0.106 impl#[Ident]new().(trait_, Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().());
72 let traits = 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().(&trait_);
73 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.);
74 let field_types = 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.type_rust-analyzer cargo postgres-derive 0.4.9 composites/Field#type_.);
75
76 quoterust-analyzer cargo quote 1.0.45 quote!! {
77 if type_.name() != #name {
78 return false;
79 }
80
81 match *type_.kind() {
82 ::postgres_types::Kind::Composite(ref fields) => {
83 if fields.len() != #num_fields {
84 return false;
85 }
86
87 fields.iter().all(|f| {
88 match f.name() {
89 #(
90 #field_names => {
91 <#field_types as ::postgres_types::#traits>::accepts(f.type_())
92 }
93 )*
94 _ => false,
95 }
96 })
97 }
98 _ => false,
99 }
100 }
101 }