Skip to content

Commit 12c2ef7

Browse files
committed
Upgrade to tokio 0.2/futures 0.3
1 parent 5517719 commit 12c2ef7

39 files changed

+210
-258
lines changed

postgres-native-tls/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ default = ["runtime"]
1616
runtime = ["tokio-postgres/runtime"]
1717

1818
[dependencies]
19+
bytes = "0.5"
1920
futures-preview = "=0.3.0-alpha.19"
2021
native-tls = "0.2"
21-
tokio-io = "=0.2.0-alpha.6"
22-
tokio-tls = "=0.3.0-alpha.6"
22+
tokio = "0.2"
23+
tokio-tls = "0.3"
2324
tokio-postgres = { version = "=0.5.0-alpha.1", path = "../tokio-postgres", default-features = false }
2425

2526
[dev-dependencies]
26-
tokio = "=0.2.0-alpha.6"
27+
tokio = { version = "0.2", features = ["full"] }
2728
postgres = { version = "=0.17.0-alpha.1", path = "../postgres" }

postgres-native-tls/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@
4848
#![doc(html_root_url = "https://docs.rs/postgres-native-tls/0.3")]
4949
#![warn(rust_2018_idioms, clippy::all, missing_docs)]
5050

51-
use futures::task::Context;
52-
use futures::Poll;
51+
use std::task::{Context, Poll};
5352
use std::future::Future;
5453
use std::io;
5554
use std::pin::Pin;
56-
use tokio_io::{AsyncRead, AsyncWrite, Buf, BufMut};
55+
use tokio::io::{AsyncRead, AsyncWrite};
56+
use bytes::{Buf, BufMut};
5757
use tokio_postgres::tls;
5858
#[cfg(feature = "runtime")]
5959
use tokio_postgres::tls::MakeTlsConnect;
6060
use tokio_postgres::tls::{ChannelBinding, TlsConnect};
61+
use std::mem::MaybeUninit;
6162

6263
#[cfg(test)]
6364
mod test;
@@ -134,7 +135,7 @@ impl<S> AsyncRead for TlsStream<S>
134135
where
135136
S: AsyncRead + AsyncWrite + Unpin,
136137
{
137-
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
138+
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [MaybeUninit<u8>]) -> bool {
138139
self.0.prepare_uninitialized_buffer(buf)
139140
}
140141

postgres-openssl/Cargo.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ default = ["runtime"]
1616
runtime = ["tokio-postgres/runtime"]
1717

1818
[dependencies]
19-
futures-preview = "=0.3.0-alpha.19"
19+
bytes = "0.5"
20+
futures = "0.3"
2021
openssl = "0.10"
21-
tokio-io = "=0.2.0-alpha.6"
22-
tokio-openssl = "=0.4.0-alpha.6"
22+
tokio = "0.2"
23+
tokio-openssl = "0.4"
2324
tokio-postgres = { version = "=0.5.0-alpha.1", path = "../tokio-postgres", default-features = false }
2425

2526
[dev-dependencies]
26-
tokio = "=0.2.0-alpha.6"
27+
tokio = { version = "0.2", features = ["full"] }
2728
postgres = { version = "=0.17.0-alpha.1", path = "../postgres" }

postgres-openssl/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
#![doc(html_root_url = "https://docs.rs/postgres-openssl/0.3")]
4343
#![warn(rust_2018_idioms, clippy::all, missing_docs)]
4444

45-
use futures::task::Context;
46-
use futures::Poll;
45+
use std::task::{Poll, Context};
4746
#[cfg(feature = "runtime")]
4847
use openssl::error::ErrorStack;
4948
use openssl::hash::MessageDigest;
@@ -57,12 +56,14 @@ use std::io;
5756
use std::pin::Pin;
5857
#[cfg(feature = "runtime")]
5958
use std::sync::Arc;
60-
use tokio_io::{AsyncRead, AsyncWrite, Buf, BufMut};
59+
use tokio::io::{AsyncRead, AsyncWrite};
60+
use bytes::{Buf, BufMut};
6161
use tokio_openssl::{HandshakeError, SslStream};
6262
use tokio_postgres::tls;
6363
#[cfg(feature = "runtime")]
6464
use tokio_postgres::tls::MakeTlsConnect;
6565
use tokio_postgres::tls::{ChannelBinding, TlsConnect};
66+
use std::mem::MaybeUninit;
6667

6768
#[cfg(test)]
6869
mod test;
@@ -156,7 +157,7 @@ impl<S> AsyncRead for TlsStream<S>
156157
where
157158
S: AsyncRead + AsyncWrite + Unpin,
158159
{
159-
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
160+
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [MaybeUninit<u8>]) -> bool {
160161
self.0.prepare_uninitialized_buffer(buf)
161162
}
162163

postgres-protocol/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ readme = "../README.md"
1111
[dependencies]
1212
base64 = "0.10"
1313
byteorder = "1.0"
14-
bytes = "0.4"
14+
bytes = "0.5"
1515
fallible-iterator = "0.2"
1616
generic-array = "0.13"
1717
hmac = "0.7"

postgres-protocol/src/lib.rs

+1-25
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,13 @@ pub enum IsNull {
3131
No,
3232
}
3333

34-
// https://github.com/tokio-rs/bytes/issues/170
35-
struct B<'a>(&'a mut BytesMut);
36-
37-
impl<'a> BufMut for B<'a> {
38-
#[inline]
39-
fn remaining_mut(&self) -> usize {
40-
usize::max_value() - self.0.len()
41-
}
42-
43-
#[inline]
44-
unsafe fn advance_mut(&mut self, cnt: usize) {
45-
self.0.advance_mut(cnt);
46-
}
47-
48-
#[inline]
49-
unsafe fn bytes_mut(&mut self) -> &mut [u8] {
50-
if !self.0.has_remaining_mut() {
51-
self.0.reserve(64);
52-
}
53-
54-
self.0.bytes_mut()
55-
}
56-
}
57-
5834
fn write_nullable<F, E>(serializer: F, buf: &mut BytesMut) -> Result<(), E>
5935
where
6036
F: FnOnce(&mut BytesMut) -> Result<IsNull, E>,
6137
E: From<io::Error>,
6238
{
6339
let base = buf.len();
64-
B(buf).put_i32_be(0);
40+
buf.put_i32(0);
6541
let size = match serializer(buf)? {
6642
IsNull::No => i32::from_usize(buf.len() - base - 4)?,
6743
IsNull::Yes => -1,

postgres-protocol/src/message/backend.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl Buffer {
301301
Some(pos) => {
302302
let start = self.idx;
303303
let end = start + pos;
304-
let cstr = self.bytes.slice(start, end);
304+
let cstr = self.bytes.slice(start..end);
305305
self.idx = end + 1;
306306
Ok(cstr)
307307
}
@@ -314,7 +314,7 @@ impl Buffer {
314314

315315
#[inline]
316316
fn read_all(&mut self) -> Bytes {
317-
let buf = self.bytes.slice_from(self.idx);
317+
let buf = self.bytes.slice(self.idx..);
318318
self.idx = self.bytes.len();
319319
buf
320320
}

0 commit comments

Comments
 (0)