| 1 | 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/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#; |
| 2 | 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/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().; |
| 3 | |
| 4 | use memchrrust-analyzer cargo memchr 2.8.3 crate/::memchrrust-analyzer cargo memchr 2.8.3 memchr/; |
| 5 | |
| 6 | use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::bytesrust-analyzer cargo bytes 1.12.1 crate/::Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#; |
| 7 | |
| 8 | 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#; |
| 9 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::iorust-analyzer cargo sqlx-postgres 0.8.3 io/::ProtocolDecoderust-analyzer cargo sqlx-core 0.8.3 io/decode/ProtocolDecode#; |
| 10 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::messagerust-analyzer cargo sqlx-postgres 0.8.3 message/::{BackendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessage#, BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#}; |
| 11 | |
| 12 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 13 | #[repr(u8)] |
| 14 | pub enum PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity# { |
| 15 | Panicrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Panic#, |
| 16 | Fatalrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Fatal#, |
| 17 | Errorrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Error#, |
| 18 | Warningrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Warning#, |
| 19 | Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Notice#, |
| 20 | Debugrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Debug#, |
| 21 | Inforust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Info#, |
| 22 | Logrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Log#, |
| 23 | } |
| 24 | |
| 25 | impl PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity# { |
| 26 | #[inline] |
| 27 | pub fn is_errorrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[PgSeverity]is_error().(self) -> bool { |
| 28 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, Selfrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[PgSeverity]::Panicrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Panic# | Selfrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[PgSeverity]::Fatalrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Fatal# | Selfrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[PgSeverity]::Errorrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Error#) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&str> for PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity# { |
| 33 | type Errorrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[PgSeverity][`TryFrom<&str>`]Error# = Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#; |
| 34 | |
| 35 | fn try_fromrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[PgSeverity][`TryFrom<&str>`]try_from().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 36 | let result = match s { |
| 37 | "PANIC" => PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Panicrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Panic#, |
| 38 | "FATAL" => PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Fatalrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Fatal#, |
| 39 | "ERROR" => PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Errorrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Error#, |
| 40 | "WARNING" => PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Warningrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Warning#, |
| 41 | "NOTICE" => PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Notice#, |
| 42 | "DEBUG" => PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Debugrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Debug#, |
| 43 | "INFO" => PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Inforust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Info#, |
| 44 | "LOG" => PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Logrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Log#, |
| 45 | |
| 46 | severity => { |
| 47 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!("unknown severity: {:?}", severity)); |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 56 | pub struct Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice# { |
| 57 | storagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#storage.: Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#, |
| 58 | severityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#severity.: PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#, |
| 59 | messagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#message.: Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize>, |
| 60 | coderust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#code.: Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize>, |
| 61 | } |
| 62 | |
| 63 | impl Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice# { |
| 64 | #[inline] |
| 65 | pub fn severityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]severity().(&self) -> PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity# { |
| 66 | self.severityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#severity. |
| 67 | } |
| 68 | |
| 69 | #[inline] |
| 70 | pub fn coderust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]code().(&self) -> &str { |
| 71 | self.get_cached_strrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]get_cached_str().(self.coderust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#code..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`][Clone]clone().()) |
| 72 | } |
| 73 | |
| 74 | #[inline] |
| 75 | pub fn messagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]message().(&self) -> &str { |
| 76 | self.get_cached_strrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]get_cached_str().(self.messagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#message..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`][Clone]clone().()) |
| 77 | } |
| 78 | |
| 79 | // Field descriptions available here: |
| 80 | // https://www.postgresql.org/docs/current/protocol-error-fields.html |
| 81 | |
| 82 | #[inline] |
| 83 | pub fn getrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]get().(&self, ty: u8) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> { |
| 84 | self.get_rawrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]get_raw().(ty).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|v| from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(v).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()) |
| 85 | } |
| 86 | |
| 87 | pub fn get_rawrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]get_raw().(&self, ty: u8) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[u8]> { |
| 88 | self.fieldsrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]fields().() |
| 89 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|(field, _)| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().field rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().ty) |
| 90 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(_, range)| &self.storagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#storage.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().range]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) |
| 91 | .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]next().() |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | impl Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice# { |
| 96 | #[inline] |
| 97 | fn fieldsrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]fields().(&self) -> Fieldsrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#<'_> { |
| 98 | Fieldsrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields# { |
| 99 | storagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#storage.: &self.storagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#storage., |
| 100 | offsetrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#offset.: 0, |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | #[inline] |
| 105 | fn get_cached_strrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]get_cached_str().(&self, cache: Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize>) -> &str { |
| 106 | // unwrap: this cannot fail at this stage |
| 107 | from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&self.storagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#storage.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().cache]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | impl ProtocolDecoderust-analyzer cargo sqlx-core 0.8.3 io/decode/ProtocolDecode#<'_> for Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice# { |
| 112 | fn decode_withrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice][`ProtocolDecode<'_, ()>`]decode_with().(buf: Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#, _: ()) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice][`ProtocolDecode<'_, ()>`], Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 113 | // In order to support PostgreSQL 9.5 and older we need to parse the localized S field. |
| 114 | // Newer versions additionally come with the V field that is guaranteed to be in English. |
| 115 | // We thus read both versions and prefer the unlocalized one if available. |
| 116 | const DEFAULT_SEVERITYrust-analyzer cargo sqlx-postgres 0.8.3 message/response/DEFAULT_SEVERITY.: PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity# = PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Logrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Log#; |
| 117 | let mut severity_v = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 118 | let mut severity_s = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 119 | let mut message = 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#0; |
| 120 | let mut code = 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#0; |
| 121 | |
| 122 | // we cache the three always present fields |
| 123 | // this enables to keep the access time down for the fields most likely accessed |
| 124 | |
| 125 | let fields = Fieldsrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields# { |
| 126 | storagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#storage.: &buf, |
| 127 | offsetrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#offset.: 0, |
| 128 | }; |
| 129 | |
| 130 | for (field, v) in fields { |
| 131 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(message.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`]is_empty().() || code.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`]is_empty().()) { |
| 132 | // stop iterating when we have the 3 fields we were looking for |
| 133 | // we assume V (severity) was the first field as it should be |
| 134 | break; |
| 135 | } |
| 136 | |
| 137 | match field { |
| 138 | b'S' => { |
| 139 | severity_s = from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`][Clone]clone().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) |
| 140 | // If the error string is not UTF-8, we have no hope of interpreting it, |
| 141 | // localized or not. The `V` field would likely fail to parse as well. |
| 142 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| notice_protocol_errrust-analyzer cargo sqlx-postgres 0.8.3 message/response/notice_protocol_err().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 143 | .try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().() |
| 144 | // If we couldn't parse the severity here, it might just be localized. |
| 145 | .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().(); |
| 146 | } |
| 147 | |
| 148 | b'V' => { |
| 149 | // Propagate errors here, because V is not localized and |
| 150 | // thus we are missing a possible variant. |
| 151 | severity_v = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#( |
| 152 | from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`][Clone]clone().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) |
| 153 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| notice_protocol_errrust-analyzer cargo sqlx-postgres 0.8.3 message/response/notice_protocol_err().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 154 | .try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 155 | ); |
| 156 | } |
| 157 | |
| 158 | b'M' => { |
| 159 | _ = from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`][Clone]clone().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| notice_protocol_errrust-analyzer cargo sqlx-postgres 0.8.3 message/response/notice_protocol_err().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 160 | message = v; |
| 161 | } |
| 162 | |
| 163 | b'C' => { |
| 164 | _ = from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`][Clone]clone().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| notice_protocol_errrust-analyzer cargo sqlx-postgres 0.8.3 message/response/notice_protocol_err().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 165 | code = v; |
| 166 | } |
| 167 | |
| 168 | // If more fields are added, make sure to check that they are valid UTF-8, |
| 169 | // otherwise the get_cached_str method will panic. |
| 170 | _ => {} |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice][`ProtocolDecode<'_, ()>`] { |
| 175 | severityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#severity.: severity_v.orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or().(severity_s).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(DEFAULT_SEVERITYrust-analyzer cargo sqlx-postgres 0.8.3 message/response/DEFAULT_SEVERITY.), |
| 176 | messagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#message., |
| 177 | coderust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#code., |
| 178 | storagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#storage.: buf, |
| 179 | }) |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | impl BackendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessage# for Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice# { |
| 184 | const FORMATrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice][BackendMessage]FORMAT.: BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat# = BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#::NoticeResponserust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#NoticeResponse#; |
| 185 | |
| 186 | fn decode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice][BackendMessage]decode_body().(buf: Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice][BackendMessage], Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 187 | // Keeping both impls for now |
| 188 | Selfrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice][BackendMessage]::decode_withrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice][`ProtocolDecode<'_, ()>`]decode_with().(buf, ()) |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | /// An iterator over each field in the Error (or Notice) response. |
| 193 | struct Fieldsrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#<'a> { |
| 194 | storagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#storage.: &'a [u8], |
| 195 | offsetrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#offset.: usize, |
| 196 | } |
| 197 | |
| 198 | impl<'a> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Fieldsrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#<'a> { |
| 199 | type Itemrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[`Fields<'a>`][Iterator]Item# = (u8, Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize>); |
| 200 | |
| 201 | fn nextrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[`Fields<'a>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[`Fields<'a>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 202 | // The fields in the response body are sequentially stored as [tag][string], |
| 203 | // ending in a final, additional [nul] |
| 204 | |
| 205 | let ty = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self.storagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#storage..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(self.offsetrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#offset.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 206 | |
| 207 | if ty rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 { |
| 208 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 209 | } |
| 210 | |
| 211 | // Consume the type byte |
| 212 | self.offsetrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#offset. = self.offsetrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#offset..checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(1)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 213 | |
| 214 | let start = self.offsetrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#offset.; |
| 215 | |
| 216 | let len = memchrrust-analyzer cargo memchr 2.8.3 memchr/memchr().(b'\0', self.storagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#storage..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(start..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 option/impl#[`Option<T>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 217 | |
| 218 | // Neither can overflow as they will always be `<= self.storage.len()`. |
| 219 | let end = self.offsetrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#offset. 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().len; |
| 220 | self.offsetrust-analyzer cargo sqlx-postgres 0.8.3 message/response/Fields#offset. = end 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; |
| 221 | |
| 222 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((ty, start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end)) |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | fn notice_protocol_errrust-analyzer cargo sqlx-postgres 0.8.3 message/response/notice_protocol_err().() -> Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error# { |
| 227 | // https://github.com/launchbadge/sqlx/issues/1144 |
| 228 | Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::Protocolrust-analyzer cargo sqlx-core 0.8.3 error/Error#Protocol#( |
| 229 | "Postgres returned a non-UTF-8 string for its error message. \ |
| 230 | This is most likely due to an error that occurred during authentication and \ |
| 231 | the default lc_messages locale is not binary-compatible with UTF-8. \ |
| 232 | See the server logs for the error details." |
| 233 | .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 234 | ) |
| 235 | } |
| 236 | |
| 237 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 238 | fn test_decode_error_responserust-analyzer cargo sqlx-postgres 0.8.3 message/response/test_decode_error_response().() { |
| 239 | const DATArust-analyzer cargo sqlx-postgres 0.8.3 message/response/DATA.: &[u8] = b"SNOTICE\0VNOTICE\0C42710\0Mextension \"uuid-ossp\" already exists, skipping\0Fextension.c\0L1656\0RCreateExtension\0\0"; |
| 240 | |
| 241 | let m = Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#::decoderust-analyzer cargo sqlx-core 0.8.3 io/decode/ProtocolDecode#decode().(Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#::from_staticrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]from_static().(DATArust-analyzer cargo sqlx-postgres 0.8.3 message/response/DATA.)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 242 | |
| 243 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 244 | m.messagerust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]message().(), |
| 245 | "extension \"uuid-ossp\" already exists, skipping" |
| 246 | ); |
| 247 | |
| 248 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(m.severityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]severity().(), PgSeverityrust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#::Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/PgSeverity#Notice#)); |
| 249 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(m.coderust-analyzer cargo sqlx-postgres 0.8.3 message/response/impl#[Notice]code().(), "42710"); |
| 250 | } |
| 251 | |
| 252 | #[cfg(all(test, not(debug_assertions)))] |
| 253 | #[benchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/bench:] |
| 254 | fn bench_error_response_get_message(b: &mut test::Bencher) { |
| 255 | const DATA: &[u8] = b"SNOTICE\0VNOTICE\0C42710\0Mextension \"uuid-ossp\" already exists, skipping\0Fextension.c\0L1656\0RCreateExtension\0\0"; |
| 256 | |
| 257 | let res = Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#::decode(test::black_box(Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#::from_static(DATA))).unwrap(); |
| 258 | |
| 259 | b.iter(|| { |
| 260 | let _ = test::black_box(&res).message(); |
| 261 | }); |
| 262 | } |
| 263 | |
| 264 | #[cfg(all(test, not(debug_assertions)))] |
| 265 | #[benchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/bench:] |
| 266 | fn bench_decode_error_response(b: &mut test::Bencher) { |
| 267 | const DATA: &[u8] = b"SNOTICE\0VNOTICE\0C42710\0Mextension \"uuid-ossp\" already exists, skipping\0Fextension.c\0L1656\0RCreateExtension\0\0"; |
| 268 | |
| 269 | b.iter(|| { |
| 270 | let _ = Noticerust-analyzer cargo sqlx-postgres 0.8.3 message/response/Notice#::decode(test::black_box(Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#::from_static(DATA))); |
| 271 | }); |
| 272 | } |