File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ use crate :: { FromSql , IsNull , ToSql , Type } ;
2+ use bytes:: buf:: BufMutExt ;
13use bytes:: { BufMut , BytesMut } ;
24use serde_1:: { Deserialize , Serialize } ;
35use serde_json_1:: Value ;
46use std:: error:: Error ;
57use std:: fmt:: Debug ;
68use std:: io:: Read ;
79
8- use crate :: { FromSql , IsNull , ToSql , Type } ;
9-
10- // https://github.com/tokio-rs/bytes/issues/170
11- struct B < ' a > ( & ' a mut BytesMut ) ;
12-
13- impl < ' a > BufMut for B < ' a > {
14- #[ inline]
15- fn remaining_mut ( & self ) -> usize {
16- usize:: max_value ( ) - self . 0 . len ( )
17- }
18-
19- #[ inline]
20- unsafe fn advance_mut ( & mut self , cnt : usize ) {
21- self . 0 . advance_mut ( cnt) ;
22- }
23-
24- #[ inline]
25- unsafe fn bytes_mut ( & mut self ) -> & mut [ u8 ] {
26- if !self . 0 . has_remaining_mut ( ) {
27- self . 0 . reserve ( 64 ) ;
28- }
29-
30- self . 0 . bytes_mut ( )
31- }
32- }
33-
3410/// A wrapper type to allow arbitrary `Serialize`/`Deserialize` types to convert to Postgres JSON values.
3511#[ derive( Debug ) ]
3612pub struct Json < T > ( pub T ) ;
6642 out : & mut BytesMut ,
6743 ) -> Result < IsNull , Box < dyn Error + Sync + Send > > {
6844 if * ty == Type :: JSONB {
69- B ( out) . put_u8 ( 1 ) ;
45+ out. put_u8 ( 1 ) ;
7046 }
71- serde_json_1:: ser:: to_writer ( B ( out) . writer ( ) , & self . 0 ) ?;
47+ serde_json_1:: ser:: to_writer ( out. writer ( ) , & self . 0 ) ?;
7248 Ok ( IsNull :: No )
7349 }
7450
You can’t perform that action at this time.
0 commit comments