[pbs-devel] [RFC v2 pxar 06/36] encoder: move to stack based state tracking
Christian Ebner
c.ebner at proxmox.com
Mon Mar 11 15:12:19 CET 2024
> On 11.03.2024 14:21 CET Fabian Grünbichler <f.gruenbichler at proxmox.com> wrote:
>
>
> nit: this could just use this.state_mut()
>
>
> nit: this could just use self.state()
>
Nope: Unfortunately the borrow check will not allow this in most of the cases,
unless I overlooked something (that's why I had to opt for the ugly version
instead of using the helper, introduced exactly for this reason).
But I will double check these cases you mentioned, maybe during refactoring
I missed some.
>
> same here (and repeated quite a few times in the remainder of this
> patch). it might be worth it to have another helper that gives you
> (&mut output, &mut state) for payload or regular output?
>
> e.g., something like this (or as two helpers dropping the bool
> parameter):
>
> + fn output_state(&mut self, payload: bool) -> io::Result<(&mut T, &mut EncoderState)> {
> + Ok((
> + if payload {
> + self.output.as_mut()
> + } else {
> + self.payload_output.as_mut().as_mut().unwrap()
> + },
> + self.state
> + .last_mut()
> + .ok_or_else(|| io_format_err!("encoder state stack underflow"))?,
> + ))
> + }
>
Okay, yes that might be handy, thanks for the suggestion.
More information about the pbs-devel
mailing list