Debian Codegraph @

src/ty_match.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#;
2
3 // These types allow the `query!()` and friends to compare a given parameter's type to
4 // an expected parameter type even if the former is behind a reference or in `Option`.
5
6 // For query parameters, Postgres gives us a single type ID which we convert to an "expected" or
7 // preferred Rust type, but there can actually be several types that are compatible for a given type
8 // in input position. E.g. for an expected parameter of `String`, we want to accept `String`,
9 // `Option<String>`, `&str` and `Option<&str>`. And for the best compiler errors we don't just
10 // want an `IsCompatible` trait (at least not without `#[on_unimplemented]` which is unstable
11 // for the foreseeable future).
12
13 // We can do this by using autoref (for method calls, the compiler adds reference ops until
14 // it finds a matching impl) with impls that technically don't overlap as a hacky form of
15 // specialization (but this works only if all types are statically known, i.e. we're not in a
16 // generic context; this should suit 99% of use cases for the macros).
17
18 #[allow(clippy::just_underscores_and_digits)]
19 pub fn same_typerust-analyzer cargo sqlx 0.8.3 ty_match/same_type().<T>(_1: &T, _2: &T) {}
20
21 pub struct WrapSamerust-analyzer cargo sqlx 0.8.3 ty_match/WrapSame#<T, U>(PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<T>, PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<U>);
22
23 impl<T, U> WrapSamerust-analyzer cargo sqlx 0.8.3 ty_match/WrapSame#<T, U> {
24 pub fn newrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`WrapSame<T, U>`]new().(_arg: &U) -> Selfrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`WrapSame<T, U>`] {
25 WrapSamerust-analyzer cargo sqlx 0.8.3 ty_match/WrapSame#(PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#)
26 }
27 }
28
29 pub trait WrapSameExtrust-analyzer cargo sqlx 0.8.3 ty_match/WrapSameExt#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
30 type Wrappedrust-analyzer cargo sqlx 0.8.3 ty_match/WrapSameExt#Wrapped#;
31
32 fn wrap_samerust-analyzer cargo sqlx 0.8.3 ty_match/WrapSameExt#wrap_same().(self) -> Self::Wrappedrust-analyzer cargo sqlx 0.8.3 ty_match/WrapSameExt#Wrapped# {
33 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("only for type resolution")
34 }
35 }
36
37 impl<T, U> WrapSameExtrust-analyzer cargo sqlx 0.8.3 ty_match/WrapSameExt# for WrapSamerust-analyzer cargo sqlx 0.8.3 ty_match/WrapSame#<T, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<U>> {
38 type Wrappedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`WrapSame<T, Option<U>>`][WrapSameExt]Wrapped# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>;
39 }
40
41 impl<T, U> WrapSameExtrust-analyzer cargo sqlx 0.8.3 ty_match/WrapSameExt# for &'_ WrapSamerust-analyzer cargo sqlx 0.8.3 ty_match/WrapSame#<T, U> {
42 type Wrappedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`&WrapSame<T, U>`][WrapSameExt]Wrapped# = T;
43 }
44
45 pub struct MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<T, U>(PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<T>, PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<U>);
46
47 impl<T, U> MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<T, U> {
48 pub fn newrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<T, U>`]new().(t: T, _u: &U) -> (T, Selfrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<T, U>`]) {
49 (t, MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#(PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#))
50 }
51 }
52
53 pub trait MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
54 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt#Matched#;
55
56 fn match_borrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt#match_borrow().(self) -> Self::Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt#Matched# {
57 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("only for type resolution")
58 }
59 }
60
61 impl<'a> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>, 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#>> {
62 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<Option<&'a str>, Option<String>>`][MatchBorrowExt]Matched# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>;
63 }
64
65 impl<'a> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a [u8]>, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>> {
66 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<Option<&'a [u8]>, Option<Vec<u8>>>`][MatchBorrowExt]Matched# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a [u8]>;
67 }
68
69 impl<'a> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> {
70 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<Option<&'a str>, Option<&'a String>>`][MatchBorrowExt]Matched# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>;
71 }
72
73 impl<'a> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a [u8]>, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>> {
74 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<Option<&'a [u8]>, Option<&'a Vec<u8>>>`][MatchBorrowExt]Matched# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a [u8]>;
75 }
76
77 impl<'a> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<&'a str, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
78 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<&'a str, String>`][MatchBorrowExt]Matched# = &'a str;
79 }
80
81 impl<'a> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<&'a [u8], Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> {
82 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<&'a [u8], Vec<u8>>`][MatchBorrowExt]Matched# = &'a [u8];
83 }
84
85 impl<T> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<&'_ T, T> {
86 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<&T, T>`][MatchBorrowExt]Matched# = T;
87 }
88
89 impl<T> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<&'_ &'_ T, T> {
90 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<&&T, T>`][MatchBorrowExt]Matched# = T;
91 }
92
93 impl<T> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<T, &'_ T> {
94 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<T, &T>`][MatchBorrowExt]Matched# = T;
95 }
96
97 impl<T> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<T, &'_ &'_ T> {
98 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<T, &&T>`][MatchBorrowExt]Matched# = T;
99 }
100
101 impl<T> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'_ T>, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>> {
102 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<Option<&T>, Option<T>>`][MatchBorrowExt]Matched# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>;
103 }
104
105 impl<T> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'_ &'_ T>, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>> {
106 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<Option<&&T>, Option<T>>`][MatchBorrowExt]Matched# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>;
107 }
108
109 impl<T> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'_ T>> {
110 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<Option<T>, Option<&T>>`][MatchBorrowExt]Matched# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>;
111 }
112
113 impl<T> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'_ &'_ T>> {
114 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<Option<T>, Option<&&T>>`][MatchBorrowExt]Matched# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>;
115 }
116
117 impl<T, U> MatchBorrowExtrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt# for &'_ MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#<T, U> {
118 type Matchedrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`&MatchBorrow<T, U>`][MatchBorrowExt]Matched# = U;
119 }
120
121 pub fn conjure_valuerust-analyzer cargo sqlx 0.8.3 ty_match/conjure_value().<T>() -> T {
122 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!()
123 }
124
125 pub fn dupe_valuerust-analyzer cargo sqlx 0.8.3 ty_match/dupe_value().<T>(_t: &T) -> T {
126 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!()
127 }
128
129 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
130 fn test_dupe_valuerust-analyzer cargo sqlx 0.8.3 ty_match/test_dupe_value().() {
131 let val = &(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(),);
132
133 if false {
134 let _: i32 = dupe_valuerust-analyzer cargo sqlx 0.8.3 ty_match/dupe_value().(&0i32);
135 let _: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# = dupe_valuerust-analyzer cargo sqlx 0.8.3 ty_match/dupe_value().(&Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().());
136 let _: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# = dupe_valuerust-analyzer cargo sqlx 0.8.3 ty_match/dupe_value().(&val.0);
137 }
138 }
139
140 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
141 fn test_wrap_samerust-analyzer cargo sqlx 0.8.3 ty_match/test_wrap_same().() {
142 if false {
143 let _: i32 = WrapSamerust-analyzer cargo sqlx 0.8.3 ty_match/WrapSame#::<i32, _>::newrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`WrapSame<T, U>`]new().(&0i32).wrap_samerust-analyzer cargo sqlx 0.8.3 ty_match/WrapSameExt#wrap_same().();
144 let _: i32 = WrapSamerust-analyzer cargo sqlx 0.8.3 ty_match/WrapSame#::<i32, _>::newrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`WrapSame<T, U>`]new().(&"hello, world!").wrap_samerust-analyzer cargo sqlx 0.8.3 ty_match/WrapSameExt#wrap_same().();
145 let _: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<i32> = WrapSamerust-analyzer cargo sqlx 0.8.3 ty_match/WrapSame#::<i32, _>::newrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`WrapSame<T, U>`]new().(&Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().())).wrap_samerust-analyzer cargo sqlx 0.8.3 ty_match/WrapSameExt#wrap_same().();
146 }
147 }
148
149 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
150 fn test_match_borrowrust-analyzer cargo sqlx 0.8.3 ty_match/test_match_borrow().() {
151 if false {
152 let (_, match_borrow) = MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#::newrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<T, U>`]new().("", &Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().());
153 let _: &str = match_borrow.match_borrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt#match_borrow().();
154
155 let (_, match_borrow) = MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#::newrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<T, U>`]new().(&&0i64, &0i64);
156 let _: i64 = match_borrow.match_borrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt#match_borrow().();
157
158 let (_, match_borrow) = MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#::newrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<T, U>`]new().(&0i64, &0i64);
159 let _: i64 = match_borrow.match_borrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt#match_borrow().();
160
161 let (_, match_borrow) = MatchBorrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrow#::newrust-analyzer cargo sqlx 0.8.3 ty_match/impl#[`MatchBorrow<T, U>`]new().(0i64, &0i64);
162 let _: i64 = match_borrow.match_borrowrust-analyzer cargo sqlx 0.8.3 ty_match/MatchBorrowExt#match_borrow().();
163 }
164 }