Fix build for real
This commit is contained in:
parent
0736382593
commit
20adbaf36b
@ -1,4 +1,4 @@
|
||||
use bytes::BytesMut;
|
||||
use bytes::{BufMut, BytesMut};
|
||||
use serde_1::{Deserialize, Serialize};
|
||||
use serde_json_1::Value;
|
||||
use std::error::Error;
|
||||
@ -7,6 +7,30 @@ use std::io::Read;
|
||||
|
||||
use crate::{FromSql, IsNull, ToSql, Type};
|
||||
|
||||
// https://github.com/tokio-rs/bytes/issues/170
|
||||
struct B<'a>(&'a mut BytesMut);
|
||||
|
||||
impl<'a> BufMut for B<'a> {
|
||||
#[inline]
|
||||
fn remaining_mut(&self) -> usize {
|
||||
usize::max_value() - self.0.len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn advance_mut(&mut self, cnt: usize) {
|
||||
self.0.advance_mut(cnt);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn bytes_mut(&mut self) -> &mut [u8] {
|
||||
if !self.0.has_remaining_mut() {
|
||||
self.0.reserve(64);
|
||||
}
|
||||
|
||||
self.0.bytes_mut()
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper type to allow arbitrary `Serialize`/`Deserialize` types to convert to Postgres JSON values.
|
||||
#[derive(Debug)]
|
||||
pub struct Json<T>(pub T);
|
||||
@ -42,9 +66,9 @@ where
|
||||
out: &mut BytesMut,
|
||||
) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
if *ty == Type::JSONB {
|
||||
out.push(1);
|
||||
B(out).put_u8(1);
|
||||
}
|
||||
serde_json_1::ser::to_writer(out, &self.0)?;
|
||||
serde_json_1::ser::to_writer(B(out).writer(), &self.0)?;
|
||||
Ok(IsNull::No)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user