cxx icon indicating copy to clipboard operation
cxx copied to clipboard

Workaround for enums with variant data?

Open Timmmm opened this issue 3 years ago • 0 comments

Is there a workaround for APIs that want to return an enum with variant data (or std::variant; #217)? The best I can think of at the moment is:

pub struct Info {
    pub variant_a Option<Box<VariantAData>>,
    pub variant_b: Option<Box<VariantBData>>,
    // ...
}

fn get_info() -> Info;

But that's not exactly elegant, plus it relies on heap allocation to avoid making Info huge. Is there a better way?

Timmmm avatar May 11 '21 12:05 Timmmm