Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Indra-db opened this issue Mar 7, 2024 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Indra-db
Copy link
Owner

Indra-db commented Mar 7, 2024

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,
}
@Indra-db Indra-db changed the title Support arbitrary sized Rust enums as components. Currently Flecs only allows 4 byte sized Enums. Support arbitrary sized Rust enums as components. Currently Flecs only allows 4 byte sized Enum fields. Mar 7, 2024
@Indra-db Indra-db moved this to Backlog in Flecs-ecs-rs Mar 7, 2024
@Indra-db Indra-db added enhancement New feature or request help wanted Extra attention is needed labels Mar 7, 2024
@Indra-db Indra-db changed the title Support arbitrary sized Rust enums as components. Currently Flecs only allows 4 byte sized Enum fields. Enhancing Support for Rust Enums with Variable Field Sizes in Flecs C Core Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Status: Backlog
Development

No branches or pull requests

1 participant