all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH pxar] decoder: sync: remove needless wrapper around `decoder::Contents`
@ 2023-08-11  9:56 Max Carrara
  2023-08-22 11:35 ` Wolfgang Bumiller
  0 siblings, 1 reply; 3+ messages in thread
From: Max Carrara @ 2023-08-11  9:56 UTC (permalink / raw)
  To: pbs-devel

Similarly to the `impl` for `tokio::io::AsyncRead` in `decoder::aio`,
this implements the `std::io::Read` trait on `decoder::Contents`
directly while removing the wrapper.

This allows `decoder::Contents` to be used in both synchronous
and asynchronous contexts.

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
---
 src/decoder/sync.rs | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/src/decoder/sync.rs b/src/decoder/sync.rs
index 5597a03..be576f8 100644
--- a/src/decoder/sync.rs
+++ b/src/decoder/sync.rs
@@ -5,7 +5,7 @@ use std::path::Path;
 use std::pin::Pin;
 use std::task::{Context, Poll};

-use crate::decoder::{self, SeqRead};
+use crate::decoder::{self, Contents, SeqRead};
 use crate::util::poll_result_once;
 use crate::Entry;

@@ -69,7 +69,7 @@ impl<T: SeqRead> Decoder<T> {

     /// Get a reader for the contents of the current entry, if the entry has contents.
     pub fn contents(&mut self) -> Option<Contents<T>> {
-        self.inner.content_reader().map(|inner| Contents { inner })
+        self.inner.content_reader()
     }

     /// Get the size of the current contents, if the entry has contents.
@@ -118,13 +118,8 @@ impl<T: io::Read> SeqRead for StandardReader<T> {
     }
 }

-/// Reader for file contents inside a pxar archive.
-pub struct Contents<'a, T: SeqRead> {
-    inner: decoder::Contents<'a, T>,
-}
-
-impl<'a, T: SeqRead> io::Read for Contents<'a, T> {
+impl<'a, T: SeqRead> io::Read for decoder::Contents<'a, T> {
     fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
-        poll_result_once(super::seq_read(&mut self.inner, buf))
+        poll_result_once(super::seq_read(self.input, buf))
     }
 }
--
2.39.2





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pbs-devel] [PATCH pxar] decoder: sync: remove needless wrapper around `decoder::Contents`
  2023-08-11  9:56 [pbs-devel] [PATCH pxar] decoder: sync: remove needless wrapper around `decoder::Contents` Max Carrara
@ 2023-08-22 11:35 ` Wolfgang Bumiller
  2023-08-24  9:47   ` Max Carrara
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfgang Bumiller @ 2023-08-22 11:35 UTC (permalink / raw)
  To: Max Carrara; +Cc: pbs-devel

sorry for the late reply

NAK

On Fri, Aug 11, 2023 at 11:56:00AM +0200, Max Carrara wrote:
> Similarly to the `impl` for `tokio::io::AsyncRead` in `decoder::aio`,
> this implements the `std::io::Read` trait on `decoder::Contents`
> directly while removing the wrapper.
> 
> This allows `decoder::Contents` to be used in both synchronous
> and asynchronous contexts.
> 
> Signed-off-by: Max Carrara <m.carrara@proxmox.com>
> ---
>  src/decoder/sync.rs | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/src/decoder/sync.rs b/src/decoder/sync.rs
> index 5597a03..be576f8 100644
> --- a/src/decoder/sync.rs
> +++ b/src/decoder/sync.rs
> @@ -5,7 +5,7 @@ use std::path::Path;
>  use std::pin::Pin;
>  use std::task::{Context, Poll};
> 
> -use crate::decoder::{self, SeqRead};
> +use crate::decoder::{self, Contents, SeqRead};
>  use crate::util::poll_result_once;
>  use crate::Entry;
> 
> @@ -69,7 +69,7 @@ impl<T: SeqRead> Decoder<T> {
> 
>      /// Get a reader for the contents of the current entry, if the entry has contents.
>      pub fn contents(&mut self) -> Option<Contents<T>> {
> -        self.inner.content_reader().map(|inner| Contents { inner })
> +        self.inner.content_reader()
>      }
> 
>      /// Get the size of the current contents, if the entry has contents.
> @@ -118,13 +118,8 @@ impl<T: io::Read> SeqRead for StandardReader<T> {
>      }
>  }
> 
> -/// Reader for file contents inside a pxar archive.
> -pub struct Contents<'a, T: SeqRead> {
> -    inner: decoder::Contents<'a, T>,
> -}
> -
> -impl<'a, T: SeqRead> io::Read for Contents<'a, T> {
> +impl<'a, T: SeqRead> io::Read for decoder::Contents<'a, T> {

`Read` is a sync interface and `poll_result_once()` *requires* it to
actually return `Ready`, and panics otherwise. This is only allowed (and
therefore "guaranteed" to work) when coming from the `sync` submodule,
so only *its* readers should implement it.

If anything, I'd go the other way round, take `pxar::decoder::Contents`
private and have one in `aio` (or just ... reexport it there :P)

>      fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
> -        poll_result_once(super::seq_read(&mut self.inner, buf))
> +        poll_result_once(super::seq_read(self.input, buf))
>      }
>  }
> --
> 2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pbs-devel] [PATCH pxar] decoder: sync: remove needless wrapper around `decoder::Contents`
  2023-08-22 11:35 ` Wolfgang Bumiller
@ 2023-08-24  9:47   ` Max Carrara
  0 siblings, 0 replies; 3+ messages in thread
From: Max Carrara @ 2023-08-24  9:47 UTC (permalink / raw)
  To: Wolfgang Bumiller; +Cc: pbs-devel

On 8/22/23 13:35, Wolfgang Bumiller wrote:
> sorry for the late reply
> 
> NAK
> 
> On Fri, Aug 11, 2023 at 11:56:00AM +0200, Max Carrara wrote:
>> Similarly to the `impl` for `tokio::io::AsyncRead` in `decoder::aio`,
>> this implements the `std::io::Read` trait on `decoder::Contents`
>> directly while removing the wrapper.
>>
>> This allows `decoder::Contents` to be used in both synchronous
>> and asynchronous contexts.
>>
>> Signed-off-by: Max Carrara <m.carrara@proxmox.com>
>> ---
>>  src/decoder/sync.rs | 13 ++++---------
>>  1 file changed, 4 insertions(+), 9 deletions(-)
>>
>> diff --git a/src/decoder/sync.rs b/src/decoder/sync.rs
>> index 5597a03..be576f8 100644
>> --- a/src/decoder/sync.rs
>> +++ b/src/decoder/sync.rs
>> @@ -5,7 +5,7 @@ use std::path::Path;
>>  use std::pin::Pin;
>>  use std::task::{Context, Poll};
>>
>> -use crate::decoder::{self, SeqRead};
>> +use crate::decoder::{self, Contents, SeqRead};
>>  use crate::util::poll_result_once;
>>  use crate::Entry;
>>
>> @@ -69,7 +69,7 @@ impl<T: SeqRead> Decoder<T> {
>>
>>      /// Get a reader for the contents of the current entry, if the entry has contents.
>>      pub fn contents(&mut self) -> Option<Contents<T>> {
>> -        self.inner.content_reader().map(|inner| Contents { inner })
>> +        self.inner.content_reader()
>>      }
>>
>>      /// Get the size of the current contents, if the entry has contents.
>> @@ -118,13 +118,8 @@ impl<T: io::Read> SeqRead for StandardReader<T> {
>>      }
>>  }
>>
>> -/// Reader for file contents inside a pxar archive.
>> -pub struct Contents<'a, T: SeqRead> {
>> -    inner: decoder::Contents<'a, T>,
>> -}
>> -
>> -impl<'a, T: SeqRead> io::Read for Contents<'a, T> {
>> +impl<'a, T: SeqRead> io::Read for decoder::Contents<'a, T> {
> 
> `Read` is a sync interface and `poll_result_once()` *requires* it to
> actually return `Ready`, and panics otherwise. This is only allowed (and
> therefore "guaranteed" to work) when coming from the `sync` submodule,
> so only *its* readers should implement it.
> 
> If anything, I'd go the other way round, take `pxar::decoder::Contents`
> private and have one in `aio` (or just ... reexport it there :P)

Very fair; in that case I'll drop this patch, as it turned out not to be
necessary on my side either way. ;-)

> 
>>      fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
>> -        poll_result_once(super::seq_read(&mut self.inner, buf))
>> +        poll_result_once(super::seq_read(self.input, buf))
>>      }
>>  }
>> --
>> 2.39.2





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-08-24  9:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-11  9:56 [pbs-devel] [PATCH pxar] decoder: sync: remove needless wrapper around `decoder::Contents` Max Carrara
2023-08-22 11:35 ` Wolfgang Bumiller
2023-08-24  9:47   ` Max Carrara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal