summaryrefslogtreecommitdiffstats
path: root/tokio/src/io/io/split.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/src/io/io/split.rs')
-rw-r--r--tokio/src/io/io/split.rs67
1 files changed, 0 insertions, 67 deletions
diff --git a/tokio/src/io/io/split.rs b/tokio/src/io/io/split.rs
deleted file mode 100644
index c3d7430e..00000000
--- a/tokio/src/io/io/split.rs
+++ /dev/null
@@ -1,67 +0,0 @@
-use crate::io::io::read_until::read_until_internal;
-use crate::io::AsyncBufRead;
-
-use futures_core::{ready, Stream};
-use pin_project::{pin_project, project};
-use std::io;
-use std::mem;
-use std::pin::Pin;
-use std::task::{Context, Poll};
-
-/// Stream for the [`split`](crate::io::AsyncBufReadExt::split) method.
-#[pin_project]
-#[derive(Debug)]
-#[must_use = "streams do nothing unless polled"]
-pub struct Split<R> {
- #[pin]
- reader: R,
- buf: Vec<u8>,
- delim: u8,
- read: usize,
-}
-
-pub(crate) fn split<R>(reader: R, delim: u8) -> Split<R>
-where
- R: AsyncBufRead,
-{
- Split {
- reader,
- buf: Vec::new(),
- delim,
- read: 0,
- }
-}
-
-impl<R: AsyncBufRead> Stream for Split<R> {
- type Item = io::Result<Vec<u8>>;
-
- #[project]
- fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
- #[project]
- let Split {
- reader,
- buf,
- delim,
- read,
- } = self.project();
-
- let n = ready!(read_until_internal(reader, cx, *delim, buf, read))?;
- if n == 0 && buf.is_empty() {
- return Poll::Ready(None);
- }
- if buf.last() == Some(&delim) {
- buf.pop();
- }
- Poll::Ready(Some(Ok(mem::replace(buf, Vec::new()))))
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn assert_unpin() {
- crate::is_unpin::<Split<()>>();
- }
-}