Skip to content

Commit

Permalink
feat: Remove pin-project-lite from the 'std' feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Dec 25, 2020
1 parent 0fea8b1 commit 32ef87b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Expand Up @@ -60,11 +60,11 @@ default = ["std"]
# Run the mp4 benchmark, requires a mp4 file named `small.mp4` in the benches directory
mp4 = []
pin-project = ["pin-project-lite"]
tokio-02 = ["pin-project", "std", "tokio-02-dep", "futures-util-03"]
tokio-03 = ["pin-project", "std", "tokio-03-dep", "futures-util-03"]
tokio = ["tokio-dep", "futures-util-03"]
futures-03 = ["pin-project", "std", "futures-io-03", "futures-util-03"]
std = ["memchr/use_std", "bytes", "pin-project"]
tokio-02 = ["pin-project", "std", "tokio-02-dep", "futures-util-03", "pin-project-lite"]
tokio-03 = ["pin-project", "std", "tokio-03-dep", "futures-util-03", "pin-project-lite"]
tokio = ["tokio-dep", "futures-util-03", "pin-project-lite"]
futures-03 = ["pin-project", "std", "futures-io-03", "futures-util-03", "pin-project-lite"]
std = ["memchr/use_std", "bytes"]

[[test]]
name = "async"
Expand Down
37 changes: 28 additions & 9 deletions src/stream/buf_reader.rs
@@ -1,19 +1,23 @@
use std::{
io::{self, BufRead, Read},
mem::MaybeUninit,
pin::Pin,
};
use std::io::{self, BufRead, Read};

#[cfg(any(
features = "futures-03",
feature = "tokio-02",
feature = "tokio-03",
feature = "tokio"
))]
use std::{mem::MaybeUninit, pin::Pin};

#[cfg(feature = "futures-util-03")]
use std::task::{Context, Poll};

#[cfg(feature = "futures-03")]
use std::future::Future;

use {
bytes::{Buf, BufMut, BytesMut},
pin_project_lite::pin_project,
};
use bytes::{Buf, BufMut, BytesMut};

#[cfg(feature = "pin-project-lite")]
use pin_project_lite::pin_project;

#[cfg(feature = "tokio-03")]
use tokio_03_dep::io::AsyncBufRead as _;
Expand All @@ -24,6 +28,7 @@ use tokio_dep::io::AsyncBufRead as _;
#[cfg(feature = "futures-util-03")]
use futures_util_03::ready;

#[cfg(feature = "pin-project-lite")]
pin_project! {
/// `BufReader` used by `Decoder` when it is constructed with [`Decoder::new_bufferless`][]
///
Expand All @@ -36,6 +41,16 @@ pin_project! {
}
}

#[cfg(not(feature = "pin-project-lite"))]
/// `BufReader` used by `Decoder` when it is constructed with [`Decoder::new_bufferless`][]
///
/// [`Decoder::new_bufferless`]: ../decoder/struct.Decoder.html#method.new_bufferless
#[derive(Debug)]
pub struct BufReader<R> {
inner: R,
buf: BytesMut,
}

impl<R> BufReader<R> {
/// Creates a new `BufReader` with a default buffer capacity. The default is currently 8 KB,
/// but may change in the future.
Expand Down Expand Up @@ -64,6 +79,7 @@ impl<R> BufReader<R> {
&mut self.inner
}

#[cfg(feature = "pin-project-lite")]
/// Gets a pinned mutable reference to the underlying reader.
///
/// It is inadvisable to directly read from the underlying reader.
Expand Down Expand Up @@ -104,6 +120,7 @@ pub trait CombineBuffer<R>: sealed::Sealed {

fn advance(&mut self, read: &mut R, len: usize);

#[cfg(feature = "pin-project-lite")]
fn advance_pin(&mut self, read: Pin<&mut R>, len: usize);
}

Expand Down Expand Up @@ -173,6 +190,7 @@ impl<R> CombineBuffer<R> for Buffer {
self.0.advance(len);
}

#[cfg(feature = "pin-project-lite")]
fn advance_pin(&mut self, _read: Pin<&mut R>, len: usize) {
self.0.advance(len);
}
Expand Down Expand Up @@ -348,6 +366,7 @@ impl<R> CombineBuffer<BufReader<R>> for Bufferless {
read.buf.advance(len);
}

#[cfg(feature = "pin-project-lite")]
fn advance_pin(&mut self, read: Pin<&mut BufReader<R>>, len: usize) {
read.project().buf.advance(len);
}
Expand Down
1 change: 1 addition & 0 deletions src/stream/decoder.rs
Expand Up @@ -107,6 +107,7 @@ impl<S, P, C> Decoder<S, P, C> {
}

#[doc(hidden)]
#[cfg(feature = "pin-project-lite")]
pub fn advance_pin<R>(&mut self, read: Pin<&mut R>, removed: usize)
where
C: CombineBuffer<R>,
Expand Down

0 comments on commit 32ef87b

Please sign in to comment.