Skip to content

Support for initializing enum variants in pin-init #59

Description

@dakr

Support for initializing enum variants in pin-init

Currently, pin-init does not support initializing enum types or variants, which is limiting in cases where pinned data must be conditionally constructed. However, this requires a way to write the discriminant of an enum.

There has been prior discussion on this topic:


Example

#[pin_data]
struct Foo {
    // ...
}

#[pin_data]
struct Bar {
    // ...
}

#[pin_data]
enum MyEnum {
    VariantA {
        #[pin]
        foo: Foo,
    },
    VariantB {
        #[pin]
        bar: Bar,
    },
}

#[pin_data]
struct Wrapper {
    #[pin]
    data: MyEnum,
    extra: u32,
}

impl Wrapper {
    fn new(init_data: impl PinInit<MyEnum>) -> impl PinInit<Self> {
        pin_init!(
            data <- init_data,
            extra: 42,
        )
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    trackingTracking issues that cannot be acted on immediately

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions