Skip to content

Commit 20adbaf

Browse files
committed
Fix build for real
1 parent 0736382 commit 20adbaf

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

postgres-types/src/serde_json_1.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bytes::BytesMut;
1+
use bytes::{BufMut, BytesMut};
22
use serde_1::{Deserialize, Serialize};
33
use serde_json_1::Value;
44
use std::error::Error;
@@ -7,6 +7,30 @@ use std::io::Read;
77

88
use crate::{FromSql, IsNull, ToSql, Type};
99

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+
1034
/// A wrapper type to allow arbitrary `Serialize`/`Deserialize` types to convert to Postgres JSON values.
1135
#[derive(Debug)]
1236
pub struct Json<T>(pub T);
@@ -42,9 +66,9 @@ where
4266
out: &mut BytesMut,
4367
) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
4468
if *ty == Type::JSONB {
45-
out.push(1);
69+
B(out).put_u8(1);
4670
}
47-
serde_json_1::ser::to_writer(out, &self.0)?;
71+
serde_json_1::ser::to_writer(B(out).writer(), &self.0)?;
4872
Ok(IsNull::No)
4973
}
5074

0 commit comments

Comments
 (0)