Debian Codegraph @

src/serde_json_1.rs

raw symbols SCIP
1 use craterust-analyzer cargo postgres-types 0.2.14 crate/::{FromSqlrust-analyzer cargo postgres-types 0.2.14 FromSql#, IsNullrust-analyzer cargo postgres-types 0.2.14 IsNull#, ToSqlrust-analyzer cargo postgres-types 0.2.14 ToSql#, Typerust-analyzer cargo postgres-types 0.2.14 Type#};
2 use bytesrust-analyzer cargo bytes 1.11.1 crate/::{BufMutrust-analyzer cargo bytes 1.11.1 buf/buf_mut/BufMut#, BytesMutrust-analyzer cargo bytes 1.11.1 bytes_mut/BytesMut#};
3 use serde_1rust-analyzer cargo serde_core 1.0.228 crate/::{Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#, Deserializerrust-analyzer cargo serde_core 1.0.228 de/Deserializer#, Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize#, Serializerrust-analyzer cargo serde_core 1.0.228 ser/Serializer#};
4 use serde_json_1rust-analyzer cargo serde_json 1.0.150 crate/::Valuerust-analyzer cargo serde_json 1.0.150 value/Value#;
5 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#;
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#;
7 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#;
8
9 /// A wrapper type to allow arbitrary `Serialize`/`Deserialize` types to convert to Postgres JSON values.
10 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
11 pub struct Jsonrust-analyzer cargo postgres-types 0.2.14 serde_json_1/Json#<T>(pub T);
12
13 impl<T: Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize#> Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize# for Jsonrust-analyzer cargo postgres-types 0.2.14 serde_json_1/Json#<T> {
14 fn serializerust-analyzer cargo postgres-types 0.2.14 serde_json_1/impl#[`Json<T>`][Serialize]serialize().<S: Serializerrust-analyzer cargo serde_core 1.0.228 ser/Serializer#>(&self, serializer: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<S::Okrust-analyzer cargo serde_core 1.0.228 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde_core 1.0.228 ser/Serializer#Error#> {
15 self.0rust-analyzer cargo postgres-types 0.2.14 serde_json_1/Json#0..serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize#serialize().(serializer)
16 }
17 }
18
19 impl<'de, T: Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#<'de>> Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#<'de> for Jsonrust-analyzer cargo postgres-types 0.2.14 serde_json_1/Json#<T> {
20 fn deserializerust-analyzer cargo postgres-types 0.2.14 serde_json_1/impl#[`Json<T>`][`Deserialize<'de>`]deserialize().<D: Deserializerrust-analyzer cargo serde_core 1.0.228 de/Deserializer#<'de>>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo postgres-types 0.2.14 serde_json_1/impl#[`Json<T>`][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde_core 1.0.228 de/Deserializer#Error#> {
21 T::deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#deserialize().(deserializer).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(Selfrust-analyzer cargo postgres-types 0.2.14 serde_json_1/impl#[`Json<T>`][`Deserialize<'de>`])
22 }
23 }
24
25 impl<'a, T> FromSqlrust-analyzer cargo postgres-types 0.2.14 FromSql#<'a> for Jsonrust-analyzer cargo postgres-types 0.2.14 serde_json_1/Json#<T>
26 where
27 T: Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#<'a>,
28 {
29 fn from_sqlrust-analyzer cargo postgres-types 0.2.14 serde_json_1/impl#[`Json<T>`][`FromSql<'a>`]from_sql().(ty: &Typerust-analyzer cargo postgres-types 0.2.14 Type#, mut raw: &'a [u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Jsonrust-analyzer cargo postgres-types 0.2.14 serde_json_1/Json#<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#>> {
30 if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ty rust-analyzer cargo postgres-types 0.2.14 impl#[Type][`PartialEq<Self>`]eq().==rust-analyzer cargo postgres-types 0.2.14 impl#[Type][`PartialEq<Self>`]eq(). rust-analyzer cargo postgres-types 0.2.14 impl#[Type][`PartialEq<Self>`]eq().Typerust-analyzer cargo postgres-types 0.2.14 Type#::JSONBrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]JSONB. {
31 let mut b = [0; 1];
32 raw.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impls/impl#[`&[u8]`][Read]read_exact().(&mut b)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
33 // We only support version 1 of the jsonb binary format
34 if b[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().1 {
35 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("unsupported JSONB encoding version".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
36 }
37 }
38 serde_json_1rust-analyzer cargo serde_json 1.0.150 crate/::derust-analyzer cargo serde_json 1.0.150 de/::from_slicerust-analyzer cargo serde_json 1.0.150 de/from_slice().(raw)
39 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(Jsonrust-analyzer cargo postgres-types 0.2.14 serde_json_1/Json#)
40 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().)
41 }
42
43 acceptsrust-analyzer cargo postgres-types 0.2.14 accepts!!(JSONrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]JSON., JSONBrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]JSONB.);
44 }
45
46 impl<T> ToSqlrust-analyzer cargo postgres-types 0.2.14 ToSql# for Jsonrust-analyzer cargo postgres-types 0.2.14 serde_json_1/Json#<T>
47 where
48 T: Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize# + Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#,
49 {
50 fn to_sqlrust-analyzer cargo postgres-types 0.2.14 serde_json_1/impl#[`Json<T>`][ToSql]to_sql().(
51 &self,
52 ty: &Typerust-analyzer cargo postgres-types 0.2.14 Type#,
53 out: &mut BytesMutrust-analyzer cargo bytes 1.11.1 bytes_mut/BytesMut#,
54 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IsNullrust-analyzer cargo postgres-types 0.2.14 IsNull#, 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#>> {
55 if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ty rust-analyzer cargo postgres-types 0.2.14 impl#[Type][`PartialEq<Self>`]eq().==rust-analyzer cargo postgres-types 0.2.14 impl#[Type][`PartialEq<Self>`]eq(). rust-analyzer cargo postgres-types 0.2.14 impl#[Type][`PartialEq<Self>`]eq().Typerust-analyzer cargo postgres-types 0.2.14 Type#::JSONBrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]JSONB. {
56 out.put_u8rust-analyzer cargo bytes 1.11.1 buf/buf_mut/BufMut#put_u8().(1);
57 }
58 serde_json_1rust-analyzer cargo serde_json 1.0.150 crate/::serrust-analyzer cargo serde_json 1.0.150 ser/::to_writerrust-analyzer cargo serde_json 1.0.150 ser/to_writer().(out.writerrust-analyzer cargo bytes 1.11.1 buf/buf_mut/BufMut#writer().(), &self.0rust-analyzer cargo postgres-types 0.2.14 serde_json_1/Json#0.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
59 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IsNullrust-analyzer cargo postgres-types 0.2.14 IsNull#::Norust-analyzer cargo postgres-types 0.2.14 IsNull#No#)
60 }
61
62 acceptsrust-analyzer cargo postgres-types 0.2.14 accepts!!(JSONrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]JSON., JSONBrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]JSONB.);
63 to_sql_checkedrust-analyzer cargo postgres-types 0.2.14 to_sql_checked!!();
64 }
65
66 impl<'a> FromSqlrust-analyzer cargo postgres-types 0.2.14 FromSql#<'a> for Valuerust-analyzer cargo serde_json 1.0.150 value/Value# {
67 fn from_sqlrust-analyzer cargo postgres-types 0.2.14 serde_json_1/impl#[Value][`FromSql<'a>`]from_sql().(ty: &Typerust-analyzer cargo postgres-types 0.2.14 Type#, raw: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Valuerust-analyzer cargo serde_json 1.0.150 value/Value#, 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#>> {
68 Jsonrust-analyzer cargo postgres-types 0.2.14 serde_json_1/Json#::<Valuerust-analyzer cargo serde_json 1.0.150 value/Value#>::from_sqlrust-analyzer cargo postgres-types 0.2.14 serde_json_1/impl#[`Json<T>`][`FromSql<'a>`]from_sql().(ty, raw).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|json| json.0rust-analyzer cargo postgres-types 0.2.14 serde_json_1/Json#0.)
69 }
70
71 acceptsrust-analyzer cargo postgres-types 0.2.14 accepts!!(JSONrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]JSON., JSONBrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]JSONB.);
72 }
73
74 impl ToSqlrust-analyzer cargo postgres-types 0.2.14 ToSql# for Valuerust-analyzer cargo serde_json 1.0.150 value/Value# {
75 fn to_sqlrust-analyzer cargo postgres-types 0.2.14 serde_json_1/impl#[Value][ToSql]to_sql().(
76 &self,
77 ty: &Typerust-analyzer cargo postgres-types 0.2.14 Type#,
78 out: &mut BytesMutrust-analyzer cargo bytes 1.11.1 bytes_mut/BytesMut#,
79 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IsNullrust-analyzer cargo postgres-types 0.2.14 IsNull#, 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#>> {
80 Jsonrust-analyzer cargo postgres-types 0.2.14 serde_json_1/Json#(self).to_sqlrust-analyzer cargo postgres-types 0.2.14 serde_json_1/impl#[`Json<T>`][ToSql]to_sql().(ty, out)
81 }
82
83 acceptsrust-analyzer cargo postgres-types 0.2.14 accepts!!(JSONrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]JSON., JSONBrust-analyzer cargo postgres-types 0.2.14 type_gen/impl#[Type]JSONB.);
84 to_sql_checkedrust-analyzer cargo postgres-types 0.2.14 to_sql_checked!!();
85 }