| 1 | use craterust-analyzer cargo postgres-types 0.2.14 crate/::{FromSqlrust-analyzer cargo postgres-types 0.2.14 FromSql#, Typerust-analyzer cargo postgres-types 0.2.14 Type#}; |
| 2 | pub use bytesrust-analyzer cargo bytes 1.11.1 crate/::BytesMutrust-analyzer cargo bytes 1.11.1 bytes_mut/BytesMut#; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#; |
| 4 | |
| 5 | pub fn read_be_i32rust-analyzer cargo postgres-types 0.2.14 private/read_be_i32().(buf: &mut &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<i32, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>> { |
| 6 | let val = buf |
| 7 | .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#4) |
| 8 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("invalid buffer size")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 9 | .try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#try_into().() |
| 10 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 11 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().buf = &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().4..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().; |
| 12 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(i32::from_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]from_be_bytes().(val)) |
| 13 | } |
| 14 | |
| 15 | pub fn read_valuerust-analyzer cargo postgres-types 0.2.14 private/read_value().<'a, T>( |
| 16 | type_: &Typerust-analyzer cargo postgres-types 0.2.14 Type#, |
| 17 | buf: &mut &'a [u8], |
| 18 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>> |
| 19 | where |
| 20 | T: FromSqlrust-analyzer cargo postgres-types 0.2.14 FromSql#<'a>, |
| 21 | { |
| 22 | let len = read_be_i32rust-analyzer cargo postgres-types 0.2.14 private/read_be_i32().(buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 23 | let value = if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().0 { |
| 24 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 25 | } else { |
| 26 | let (head, tail) = buf |
| 27 | .split_at_checkedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at_checked().(len as usize) |
| 28 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("invalid buffer size")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 29 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().buf = tail; |
| 30 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(head) |
| 31 | }; |
| 32 | T::from_sql_nullablerust-analyzer cargo postgres-types 0.2.14 FromSql#from_sql_nullable().(type_, value) |
| 33 | } |