qemu-rust
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 08/11] rust/block: Add driver module


From: Kevin Wolf
Subject: Re: [PATCH 08/11] rust/block: Add driver module
Date: Wed, 12 Feb 2025 18:32:29 +0100

Am 12.02.2025 um 17:43 hat Paolo Bonzini geschrieben:
> On 2/11/25 22:43, Kevin Wolf wrote:
> > +    /// Reads data from the child node into a linear typed buffer.
> > +    pub async fn read<T: IoBuffer + ?Sized>(&self, offset: u64, buf: &mut 
> > T) -> io::Result<()> {
> > +        unsafe {
> > +            self.read_raw(offset, buf.buffer_len(), buf.buffer_mut_ptr())
> > +                .await
> > +        }
> > +    }
> > +
> > +    /// Reads data from the child node into a linear, potentially 
> > uninitialised typed buffer.
> > +    pub async fn read_uninit<T: SizedIoBuffer>(
> > +        &self,
> > +        offset: u64,
> > +        mut buf: MaybeUninit<T>,
> 
> I think Rust doesn't guarantee no copies here, so maybe this could be

Do you think that in practice the compiler won't optimise the copy away?
Or is this more of a theoretical concern?

>    pub async fn read_uninit<T: SizedIoBuffer>(
>        &self,
>        offset: u64,
>        buf: &mut MaybeUninit<T>,
>     ) -> io::Result<&mut T>
> 
> using assume_init_mut().

Are you sure that callers are ok with only getting a &mut T rather than
an owned T?

Kevin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]