| 1 | use atoirust-analyzer cargo atoi 2.0.0 crate/::atoirust-analyzer cargo atoi 2.0.0 atoi().; |
| 2 | use memchrrust-analyzer cargo memchr 2.8.3 crate/::memrchrrust-analyzer cargo memchr 2.8.3 memchr/memrchr().; |
| 3 | 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#; |
| 4 | |
| 5 | 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#; |
| 6 | 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#}; |
| 7 | |
| 8 | #[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:)] |
| 9 | pub struct CommandCompleterust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/CommandComplete# { |
| 10 | /// The command tag. This is usually a single word that identifies which SQL command |
| 11 | /// was completed. |
| 12 | tagrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/CommandComplete#tag.: Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#, |
| 13 | } |
| 14 | |
| 15 | impl BackendMessagerust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessage# for CommandCompleterust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/CommandComplete# { |
| 16 | const FORMATrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/impl#[CommandComplete][BackendMessage]FORMAT.: BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat# = BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#::CommandCompleterust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#CommandComplete#; |
| 17 | |
| 18 | fn decode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/impl#[CommandComplete][BackendMessage]decode_body().(bytes: 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/command_complete/impl#[CommandComplete][BackendMessage], Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 19 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(CommandCompleterust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/CommandComplete# { tagrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/CommandComplete#tag.: bytes }) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | impl CommandCompleterust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/CommandComplete# { |
| 24 | /// Returns the number of rows affected. |
| 25 | /// If the command does not return rows (e.g., "CREATE TABLE"), returns 0. |
| 26 | pub fn rows_affectedrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/impl#[CommandComplete]rows_affected().(&self) -> u64 { |
| 27 | // Look backwards for the first SPACE |
| 28 | memrchrrust-analyzer cargo memchr 2.8.3 memchr/memrchr().(b' ', &self.tagrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/CommandComplete#tag.) |
| 29 | // This is either a word or the number of rows affected |
| 30 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|i| atoirust-analyzer cargo atoi 2.0.0 atoi().(&self.tagrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/CommandComplete#tag.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().(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)..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().)) |
| 31 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0) |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 36 | fn test_decode_command_complete_for_insertrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/test_decode_command_complete_for_insert().() { |
| 37 | const DATArust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/DATA.: &[u8] = b"INSERT 0 1214\0"; |
| 38 | |
| 39 | let cc = CommandCompleterust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/CommandComplete#::decode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/impl#[CommandComplete][BackendMessage]decode_body().(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/command_complete/DATA.)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 40 | |
| 41 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cc.rows_affectedrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/impl#[CommandComplete]rows_affected().(), 1214); |
| 42 | } |
| 43 | |
| 44 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 45 | fn test_decode_command_complete_for_beginrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/test_decode_command_complete_for_begin().() { |
| 46 | const DATArust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/DATA.: &[u8] = b"BEGIN\0"; |
| 47 | |
| 48 | let cc = CommandCompleterust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/CommandComplete#::decode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/impl#[CommandComplete][BackendMessage]decode_body().(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/command_complete/DATA.)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 49 | |
| 50 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cc.rows_affectedrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/impl#[CommandComplete]rows_affected().(), 0); |
| 51 | } |
| 52 | |
| 53 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 54 | fn test_decode_command_complete_for_updaterust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/test_decode_command_complete_for_update().() { |
| 55 | const DATArust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/DATA.: &[u8] = b"UPDATE 5\0"; |
| 56 | |
| 57 | let cc = CommandCompleterust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/CommandComplete#::decode_bodyrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/impl#[CommandComplete][BackendMessage]decode_body().(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/command_complete/DATA.)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 58 | |
| 59 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cc.rows_affectedrust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/impl#[CommandComplete]rows_affected().(), 5); |
| 60 | } |
| 61 | |
| 62 | #[cfg(all(test, not(debug_assertions)))] |
| 63 | #[benchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/bench:] |
| 64 | fn bench_decode_command_complete(b: &mut test::Bencher) { |
| 65 | const DATA: &[u8] = b"INSERT 0 1214\0"; |
| 66 | |
| 67 | b.iter(|| { |
| 68 | let _ = CommandCompleterust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/CommandComplete#::decode_body(test::black_box(Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#::from_static(DATA))); |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | #[cfg(all(test, not(debug_assertions)))] |
| 73 | #[benchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/bench:] |
| 74 | fn bench_decode_command_complete_rows_affected(b: &mut test::Bencher) { |
| 75 | const DATA: &[u8] = b"INSERT 0 1214\0"; |
| 76 | |
| 77 | let data = CommandCompleterust-analyzer cargo sqlx-postgres 0.8.3 message/command_complete/CommandComplete#::decode_body(Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#::from_static(DATA)).unwrap(); |
| 78 | |
| 79 | b.iter(|| { |
| 80 | let _rows = test::black_box(&data).rows_affected(); |
| 81 | }); |
| 82 | } |