Skip to content

Commit 4a51a7e

Browse files
committed
Fix serde-json
1 parent 7eb61c7 commit 4a51a7e

File tree

1 file changed

+4
-28
lines changed

1 file changed

+4
-28
lines changed

postgres-types/src/serde_json_1.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,12 @@
1+
use crate::{FromSql, IsNull, ToSql, Type};
2+
use bytes::buf::BufMutExt;
13
use bytes::{BufMut, BytesMut};
24
use serde_1::{Deserialize, Serialize};
35
use serde_json_1::Value;
46
use std::error::Error;
57
use std::fmt::Debug;
68
use 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)]
3612
pub struct Json<T>(pub T);
@@ -66,9 +42,9 @@ where
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

0 commit comments

Comments
 (0)