Take Receiver by value in ReadableRx::new

It would remove the lifetime and make reasoning the code much easier.

It would also unblock the next commit I am going to make.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-13 01:05:07 +10:00
parent b4e61161f2
commit 8ef1e56fcc
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
2 changed files with 10 additions and 10 deletions

View file

@ -219,11 +219,11 @@ where
extract_impl( extract_impl(
stream, stream,
Box::new(move |mut rx| { Box::new(move |rx| {
fs::create_dir_all(path.parent().unwrap())?; fs::create_dir_all(path.parent().unwrap())?;
extract_compressed_from_readable::<DummyVisitor, _>( extract_compressed_from_readable::<DummyVisitor, _>(
ReadableRx::new(&mut rx), ReadableRx::new(rx),
fmt, fmt,
Op::UnpackToPath(&path), Op::UnpackToPath(&path),
) )
@ -242,8 +242,8 @@ where
{ {
extract_impl( extract_impl(
stream, stream,
Box::new(move |mut rx| { Box::new(move |rx| {
extract_compressed_from_readable(ReadableRx::new(&mut rx), fmt, Op::Visit(&mut visitor)) extract_compressed_from_readable(ReadableRx::new(rx), fmt, Op::Visit(&mut visitor))
.map(|_| visitor) .map(|_| visitor)
}), }),
) )

View file

@ -7,13 +7,13 @@ use tokio::sync::mpsc::Receiver;
use super::async_extracter::Content; use super::async_extracter::Content;
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct ReadableRx<'a> { pub(crate) struct ReadableRx {
rx: &'a mut Receiver<Content>, rx: Receiver<Content>,
bytes: Bytes, bytes: Bytes,
} }
impl<'a> ReadableRx<'a> { impl ReadableRx {
pub(crate) fn new(rx: &'a mut Receiver<Content>) -> Self { pub(crate) fn new(rx: Receiver<Content>) -> Self {
Self { Self {
rx, rx,
bytes: Bytes::new(), bytes: Bytes::new(),
@ -21,7 +21,7 @@ impl<'a> ReadableRx<'a> {
} }
} }
impl Read for ReadableRx<'_> { impl Read for ReadableRx {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
if buf.is_empty() { if buf.is_empty() {
return Ok(0); return Ok(0);
@ -43,7 +43,7 @@ impl Read for ReadableRx<'_> {
} }
} }
impl BufRead for ReadableRx<'_> { impl BufRead for ReadableRx {
fn fill_buf(&mut self) -> io::Result<&[u8]> { fn fill_buf(&mut self) -> io::Result<&[u8]> {
let bytes = &mut self.bytes; let bytes = &mut self.bytes;
if !bytes.has_remaining() { if !bytes.has_remaining() {