Re: [PATCH v3 08/10] rust: pci: add SR-IOV enable and disable tokens

From: Zhi Wang

Date: Sun Oct 04 2026 - 02:18:00 EST


On Wed, 30 Sep 2026 16:25:36 +0200
"Danilo Krummrich" <dakr@xxxxxxxxxx> wrote:

> On Wed Sep 30, 2026 at 12:18 PM CEST, Zhi Wang wrote:
> > +pub struct SriovEnable<'callback> {
>

snip

> > +/// Enabled VFs awaiting successful completion of `sriov_enable()`.
> > +pub struct SriovEnabled<'callback> {
> > + pdev: Option<&'callback
> > Device<device::CoreInternal<'callback>>>,
>
> This doesn't need to be an Option.
>

I realize that with ManullayDrop, I don't need Option to be used as the
Guard now. Thanks!

> > + num_vfs: c_int,
> > +}
> > +
> > +impl SriovEnabled<'_> {
> > + #[expect(dead_code)]
> > + fn disarm(mut self) -> c_int {
> > + self.pdev = None;
> > + self.num_vfs
>
> Instead of the Option dance, you can use ManuallyDrop to prevent the
> destructor from running.
>
> > + }
> > +}
> > +
> > +impl Drop for SriovEnabled<'_> {
> > + fn drop(&mut self) {
> > + if let Some(pdev) = self.pdev.take() {
> > + pdev.disable_sriov();
> > + }
> > + }
> > +}