Debian Codegraph @

src/connection/stream.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#, Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#};
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#;
4
5 use futures_channelrust-analyzer cargo futures-channel 0.3.34 crate/::mpscrust-analyzer cargo futures-channel 0.3.34 mpsc/::UnboundedSenderrust-analyzer cargo futures-channel 0.3.34 mpsc/UnboundedSender#;
6 use futures_utilrust-analyzer cargo futures-util 0.3.34 crate/::SinkExtrust-analyzer cargo futures-util 0.3.34 sink/SinkExt#;
7 use logrust-analyzer cargo log 0.4.34 crate/::Levelrust-analyzer cargo log 0.4.34 Level#;
8 use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::bytesrust-analyzer cargo bytes 1.12.1 crate/::Bufrust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#;
9
10 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::connectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/::tlsrust-analyzer cargo sqlx-postgres 0.8.3 connection/tls/::MaybeUpgradeTlsrust-analyzer cargo sqlx-postgres 0.8.3 connection/tls/MaybeUpgradeTls#;
11 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::errorrust-analyzer cargo sqlx-postgres 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#;
12 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::messagerust-analyzer cargo sqlx-postgres 0.8.3 message/::{
13 BackendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessage#, BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#, EncodeMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/EncodeMessage#, FrontendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessage#, Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#, Notificationrust-analyzer cargo sqlx-postgres 0.8.3 message/notification/Notification#,
14 ParameterStatusrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_status/ParameterStatus#, ReceivedMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/ReceivedMessage#,
15 };
16 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::netrust-analyzer cargo sqlx-core 0.8.3 net/::{selfrust-analyzer cargo sqlx-core 0.8.3 net/, BufferedSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#, Socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#};
17 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::{PgConnectOptionsrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#, PgDatabaseErrorrust-analyzer cargo sqlx-postgres 0.8.3 error/PgDatabaseError#, PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#};
18
19 // the stream is a separate type from the connection to uphold the invariant where an instantiated
20 // [PgConnection] is a **valid** connection to postgres
21
22 // when a new connection is asked for, we work directly on the [PgStream] type until the
23 // connection is fully established
24
25 // in other words, `self` in any PgConnection method is a live connection to postgres that
26 // is fully prepared to receive queries
27
28 pub struct PgStreamrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream# {
29 // A trait object is okay here as the buffering amortizes the overhead of both the dynamic
30 // function call as well as the syscall.
31 innerrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#inner.: BufferedSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#>>,
32
33 // buffer of unreceived notification messages from `PUBLISH`
34 // this is set when creating a PgListener and only written to if that listener is
35 // re-used for query execution in-between receiving messages
36 pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) notificationsrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#notifications.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<UnboundedSenderrust-analyzer cargo futures-channel 0.3.34 mpsc/UnboundedSender#<Notificationrust-analyzer cargo sqlx-postgres 0.8.3 message/notification/Notification#>>,
37
38 pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) parameter_statusesrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#parameter_statuses.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
39
40 pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) server_version_numrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#server_version_num.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u32>,
41 }
42
43 impl PgStreamrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream# {
44 pub(superrust-analyzer cargo sqlx-postgres 0.8.3 connection/) async fn connectrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]connect().(options: &PgConnectOptionsrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream], Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
45 let socket_result = match options.fetch_socketrust-analyzer cargo sqlx-postgres 0.8.3 options/impl#[PgConnectOptions]fetch_socket().() {
46 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref path) => netrust-analyzer cargo sqlx-core 0.8.3 net/::connect_udsrust-analyzer cargo sqlx-core 0.8.3 net/socket/connect_uds().(path, MaybeUpgradeTlsrust-analyzer cargo sqlx-postgres 0.8.3 connection/tls/MaybeUpgradeTls#(options)).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
47 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => netrust-analyzer cargo sqlx-core 0.8.3 net/::connect_tcprust-analyzer cargo sqlx-core 0.8.3 net/socket/connect_tcp().(&options.hostrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#host., options.portrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#port., MaybeUpgradeTlsrust-analyzer cargo sqlx-postgres 0.8.3 connection/tls/MaybeUpgradeTls#(options)).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
48 };
49
50 let socket = socket_result?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
51
52 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream] {
53 innerrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#inner.: BufferedSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#::newrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]new().(socket),
54 notificationsrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#notifications.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
55 parameter_statusesrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#parameter_statuses.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`][Default]default().(),
56 server_version_numrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#server_version_num.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
57 })
58 }
59
60 #[inline(always)]
61 pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) fn write_msgrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]write_msg().(&mut self, message: impl FrontendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessage#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
62 self.writerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]write().(EncodeMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/EncodeMessage#(message))
63 }
64
65 pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) async fn sendrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]send().<T>(&mut self, message: T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>
66 where
67 T: FrontendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/FrontendMessage#,
68 {
69 self.write_msgrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]write_msg().(message)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
70 self.flushrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]flush().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
71 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
72 }
73
74 // Expect a specific type and format
75 pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) async fn recv_expectrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]recv_expect().<B: BackendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessage#>(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<B, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
76 self.recvrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]recv().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..decoderust-analyzer cargo sqlx-postgres 0.8.3 message/impl#[ReceivedMessage]decode().()
77 }
78
79 pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) async fn recv_uncheckedrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]recv_unchecked().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<ReceivedMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/ReceivedMessage#, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
80 // NOTE: to not break everything, this should be cancel-safe;
81 // DO NOT modify `buf` unless a full message has been read
82 self.innerrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#inner.
83 .try_readrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]try_read().(|buf| {
84 // all packets in postgres start with a 5-byte header
85 // this header contains the message type and the total length of the message
86 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut header) = buf.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#5) else {
87 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#::Continuerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#Continue#(5));
88 };
89
90 let format = BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#::try_from_u8rust-analyzer cargo sqlx-postgres 0.8.3 message/impl#[BackendMessageFormat]try_from_u8().(header.get_u8rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u8().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
91
92 let message_len = header.get_u32rust-analyzer cargo bytes 1.12.1 buf/buf_impl/Buf#get_u32().() as usize;
93
94 let expected_len = message_len
95 .checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(1)
96 // this shouldn't really happen but is mostly a sanity check
97 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
98 err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!("message_len + 1 overflows usize: {message_len}")
99 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
100
101 if buf.lenrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().expected_len {
102 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#::Continuerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#Continue#(expected_len));
103 }
104
105 // `buf` SHOULD NOT be modified ABOVE this line
106
107 // pop off the format code since it's not counted in `message_len`
108 buf.advancerust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut][Buf]advance().(1);
109
110 // consume the message, including the length prefix
111 let mut contents = buf.split_torust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]split_to().(message_len).freezerust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]freeze().();
112
113 // cut off the length prefix
114 contents.advancerust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes][Buf]advance().(4);
115
116 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#::Breakrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#Break#(ReceivedMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/ReceivedMessage# { formatrust-analyzer cargo sqlx-postgres 0.8.3 message/ReceivedMessage#format., contentsrust-analyzer cargo sqlx-postgres 0.8.3 message/ReceivedMessage#contents. }))
117 })
118 .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
119 }
120
121 // Get the next message from the server
122 // May wait for more data from the server
123 pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) async fn recvrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]recv().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<ReceivedMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/ReceivedMessage#, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
124 loop {
125 let message = self.recv_uncheckedrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]recv_unchecked().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
126
127 match message.formatrust-analyzer cargo sqlx-postgres 0.8.3 message/ReceivedMessage#format. {
128 BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#::ErrorResponserust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#ErrorResponse# => {
129 // An error returned from the database server.
130 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(message.decoderust-analyzer cargo sqlx-postgres 0.8.3 message/impl#[ReceivedMessage]decode().::<PgDatabaseErrorrust-analyzer cargo sqlx-postgres 0.8.3 error/PgDatabaseError#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
131 }
132
133 BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#::NotificationResponserust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#NotificationResponse# => {
134 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(buffer) = &mut self.notificationsrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#notifications. {
135 let notification: Notificationrust-analyzer cargo sqlx-postgres 0.8.3 message/notification/Notification# = message.decoderust-analyzer cargo sqlx-postgres 0.8.3 message/impl#[ReceivedMessage]decode().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
136 let _ = buffer.sendrust-analyzer cargo futures-util 0.3.34 sink/SinkExt#send().(notification).rust-analyzer cargo futures-util 0.3.34 sink/send/impl#[`Send<'_, Si, Item>`][Future]poll().awaitrust-analyzer cargo futures-util 0.3.34 sink/send/impl#[`Send<'_, Si, Item>`][Future]poll().;
137
138 continue;
139 }
140 }
141
142 BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#::ParameterStatusrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#ParameterStatus# => {
143 // informs the frontend about the current (initial)
144 // setting of backend parameters
145
146 let ParameterStatusrust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_status/ParameterStatus# { namerust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_status/ParameterStatus#name., valuerust-analyzer cargo sqlx-postgres 0.8.3 message/parameter_status/ParameterStatus#value. } = message.decoderust-analyzer cargo sqlx-postgres 0.8.3 message/impl#[ReceivedMessage]decode().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
147 // TODO: handle `client_encoding`, `DateStyle` change
148
149 match name.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() {
150 "server_version" => {
151 self.server_version_numrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#server_version_num. = parse_server_versionrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/parse_server_version().(&value);
152 }
153 _ => {
154 self.parameter_statusesrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#parameter_statuses..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(name, value);
155 }
156 }
157
158 continue;
159 }
160
161 BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#::NoticeResponserust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#NoticeResponse# => {
162 // do we need this to be more configurable?
163 // if you are reading this comment and think so, open an issue
164
165 let notice: Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice# = message.decoderust-analyzer cargo sqlx-postgres 0.8.3 message/impl#[ReceivedMessage]decode().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
166
167 let (log_level, tracing_level) = match notice.severityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]severity().() {
168 PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Fatalrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Fatal# | PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Panicrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Panic# | PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Errorrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Error# => {
169 (Levelrust-analyzer cargo log 0.4.34 Level#::Errorrust-analyzer cargo log 0.4.34 Level#Error#, tracingrust-analyzer cargo tracing 0.1.44 crate/::Levelrust-analyzer cargo tracing-core 0.1.36 metadata/Level#::ERRORrust-analyzer cargo tracing-core 0.1.36 metadata/impl#[Level]ERROR.)
170 }
171 PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Warningrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Warning# => (Levelrust-analyzer cargo log 0.4.34 Level#::Warnrust-analyzer cargo log 0.4.34 Level#Warn#, tracingrust-analyzer cargo tracing 0.1.44 crate/::Levelrust-analyzer cargo tracing-core 0.1.36 metadata/Level#::WARNrust-analyzer cargo tracing-core 0.1.36 metadata/impl#[Level]WARN.),
172 PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Notice# => (Levelrust-analyzer cargo log 0.4.34 Level#::Inforust-analyzer cargo log 0.4.34 Level#Info#, tracingrust-analyzer cargo tracing 0.1.44 crate/::Levelrust-analyzer cargo tracing-core 0.1.36 metadata/Level#::INFOrust-analyzer cargo tracing-core 0.1.36 metadata/impl#[Level]INFO.),
173 PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Debugrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Debug# => (Levelrust-analyzer cargo log 0.4.34 Level#::Debugrust-analyzer cargo log 0.4.34 Level#Debug#, tracingrust-analyzer cargo tracing 0.1.44 crate/::Levelrust-analyzer cargo tracing-core 0.1.36 metadata/Level#::DEBUGrust-analyzer cargo tracing-core 0.1.36 metadata/impl#[Level]DEBUG.),
174 PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Inforust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Info# | PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Logrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Log# => (Levelrust-analyzer cargo log 0.4.34 Level#::Tracerust-analyzer cargo log 0.4.34 Level#Trace#, tracingrust-analyzer cargo tracing 0.1.44 crate/::Levelrust-analyzer cargo tracing-core 0.1.36 metadata/Level#::TRACErust-analyzer cargo tracing-core 0.1.36 metadata/impl#[Level]TRACE.),
175 };
176
177 let log_is_enabled = logrust-analyzer cargo log 0.4.34 crate/::log_enabledrust-analyzer cargo log 0.4.34 macros/log_enabled!!(
178 target: "sqlx::postgres::notice",
179 log_level
180 ) || sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::private_tracing_dynamic_enabledrust-analyzer cargo sqlx-core 0.8.3 logger/private_tracing_dynamic_enabled!!(
181 target: "sqlx::postgres::notice",
182 tracing_level
183 );
184 if log_is_enabled {
185 sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::private_tracing_dynamic_eventrust-analyzer cargo sqlx-core 0.8.3 logger/private_tracing_dynamic_event!!(
186 target: "sqlx::postgres::notice",
187 tracing_level,
188 message = notice.messagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]message().()
189 );
190 }
191
192 continue;
193 }
194
195 _ => {}
196 }
197
198 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(message);
199 }
200 }
201 }
202
203 impl Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for PgStreamrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream# {
204 type Targetrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream][Deref]Target# = BufferedSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/BufferedSocket#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#>>;
205
206 #[inline]
207 fn derefrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream][Deref]deref().(&self) -> &Selfrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream][Deref]::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# {
208 &self.innerrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#inner.
209 }
210 }
211
212 impl DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut# for PgStreamrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream# {
213 #[inline]
214 fn deref_mutrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream][DerefMut]deref_mut().(&mut self) -> &mut Selfrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream][DerefMut]::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# {
215 &mut self.innerrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#inner.
216 }
217 }
218
219 // reference:
220 // https://github.com/postgres/postgres/blob/6feebcb6b44631c3dc435e971bd80c2dd218a5ab/src/interfaces/libpq/fe-exec.c#L1030-L1065
221 fn parse_server_versionrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/parse_server_version().(s: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u32> {
222 let mut parts = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<u32>::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(3);
223
224 let mut from = 0;
225 let mut chs = s.char_indicesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]char_indices().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
226 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((i, ch)) = chs.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().() {
227 match ch {
228 '.' => {
229 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(num) = u32::from_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32][FromStr]from_str().(&s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().from..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) {
230 parts.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(num);
231 from = i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1;
232 } else {
233 break;
234 }
235 }
236 _ if ch.is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_digit().() => {
237 if chs.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
238 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(num) = u32::from_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32][FromStr]from_str().(&s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().from..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) {
239 parts.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(num);
240 }
241 break;
242 }
243 }
244 _ => {
245 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(num) = u32::from_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32][FromStr]from_str().(&s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().from..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) {
246 parts.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(num);
247 }
248 break;
249 }
250 };
251 }
252
253 let version_num = match parts.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().() {
254 [major, minor, rev] => (100 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<&u32>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<&u32>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<&u32>`]mul().major rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<&u32>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<&u32>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<&u32>`]add().minor) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().100 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<&u32>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<&u32>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<&u32>`]add().rev,
255 [major, minor] if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().major rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge().10 => 100 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().100 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<&u32>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<&u32>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<&u32>`]mul().major rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<&u32>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<&u32>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<&u32>`]add().minor,
256 [major, minor] => (100 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<&u32>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<&u32>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<&u32>`]mul().major rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<&u32>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<&u32>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<&u32>`]add().minor) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().100,
257 [major] => 100 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().100 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<&u32>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<&u32>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<&u32>`]mul().major,
258 _ => return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
259 };
260
261 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(version_num)
262 }
263
264 #[cfg(test)]
265 mod testsrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/tests/ {
266 use superrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/::parse_server_versionrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/parse_server_version().;
267
268 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
269 fn test_parse_server_version_numrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/tests/test_parse_server_version_num().() {
270 // old style
271 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_server_versionrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/parse_server_version().("9.6.1"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(90601));
272 // new style
273 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_server_versionrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/parse_server_version().("10.1"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(100001));
274 // old style without minor version
275 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_server_versionrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/parse_server_version().("9.6devel"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(90600));
276 // new style without minor version, e.g. */
277 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_server_versionrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/parse_server_version().("10devel"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(100000));
278 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_server_versionrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/parse_server_version().("13devel87"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(130000));
279 // unknown
280 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_server_versionrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/parse_server_version().("unknown"), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
281 }
282 }