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

View file

@ -7,13 +7,13 @@ use tokio::sync::mpsc::Receiver;
use super::async_extracter::Content;
#[derive(Debug)]
pub(crate) struct ReadableRx<'a> {
rx: &'a mut Receiver<Content>,
pub(crate) struct ReadableRx {
rx: Receiver<Content>,
bytes: Bytes,
}
impl<'a> ReadableRx<'a> {
pub(crate) fn new(rx: &'a mut Receiver<Content>) -> Self {
impl ReadableRx {
pub(crate) fn new(rx: Receiver<Content>) -> Self {
Self {
rx,
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> {
if buf.is_empty() {
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]> {
let bytes = &mut self.bytes;
if !bytes.has_remaining() {