Skip to content

Enhancing Support for Rust Enums with Variable Field Sizes in Flecs C Core #13

@Indra-db

Description

@Indra-db

The current implementation of the binding is restricted to handling Enum components where each field is mandated to be 4 bytes in size. This contrasts with Rust's default behavior, which allocates 1 byte per field. Moreover, Rust Enums are capable of accommodating fields of any size, including complex data structures akin to C++'s std::variant.

To extend our support to encompass fully-featured Rust Enums, modifications are necessitated within the C core of Flecs. Preliminary investigations suggest that these adjustments are feasible.

The existing approach to facilitate the compatibility of enum components entails annotating them with Repr(C), ensuring that each field occupies 4 bytes.

#[repr(C)]
#[derive(Debug, Default, Clone, Component)]
enum Color {
    Green,
    #[default]
    Red,
    Blue,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions