File tree 1 file changed +4
-28
lines changed 1 file changed +4
-28
lines changed Original file line number Diff line number Diff line change
1
+ use crate :: { FromSql , IsNull , ToSql , Type } ;
2
+ use bytes:: buf:: BufMutExt ;
1
3
use bytes:: { BufMut , BytesMut } ;
2
4
use serde_1:: { Deserialize , Serialize } ;
3
5
use serde_json_1:: Value ;
4
6
use std:: error:: Error ;
5
7
use std:: fmt:: Debug ;
6
8
use std:: io:: Read ;
7
9
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
-
34
10
/// A wrapper type to allow arbitrary `Serialize`/`Deserialize` types to convert to Postgres JSON values.
35
11
#[ derive( Debug ) ]
36
12
pub struct Json < T > ( pub T ) ;
66
42
out : & mut BytesMut ,
67
43
) -> Result < IsNull , Box < dyn Error + Sync + Send > > {
68
44
if * ty == Type :: JSONB {
69
- B ( out) . put_u8 ( 1 ) ;
45
+ out. put_u8 ( 1 ) ;
70
46
}
71
- serde_json_1:: ser:: to_writer ( B ( out) . writer ( ) , & self . 0 ) ?;
47
+ serde_json_1:: ser:: to_writer ( out. writer ( ) , & self . 0 ) ?;
72
48
Ok ( IsNull :: No )
73
49
}
74
50
You can’t perform that action at this time.
0 commit comments