bevyengine / bevyengine/bevy

Make ComponentDescriptor const

Open
#3,365 5 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Code-Quality C-Performance D-Straightforward S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?

The `ComponentDescriptor` is always the same for each component type.

## What solution would you like?

Create an associated constant on the `Component` and `Resource` trait, which stores the existing information.

Constify all of the methods on `ComponentDescriptor`, then use those to initialize this information at compile-time.

We can also do this for `NonSend` resources by creating a simple trait for them.

## What alternative(s) have you considered?

Enable the feature flags and do it now!

## Additional context

This is blocked by several (!) unstable `rustc` features.

1. trait bounds other than `Sized` on const fn parameters are unstable
2. `std::any::type_name` is not yet stable as a const fn
3. `TypeId::of` is not yet stable as a const fn
4. function pointer casts are not allowed in constant functions

https://github.com/rust-lang/rust/issues/57563 is the relevant tracking issue

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.