amethyst / amethyst/specs

Default Component Impl

Aperta
#640 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
feature-request
Lingua principale
Rust
Stelle
2.6k
Fork
215
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## Description
Add a feature `auto-component` (or maybe `specialization`) that uses the nightly feature `specialization` to make everything a component. I noticed there already is a nightly feature, but I wanted to keep them separate for this example.
```rust
#![cfg_attr(feature = "auto-component", feature(specialization))]

pub trait Component: Any + Sized {
/// Associated storage type for this component.
type Storage: UnprotectedStorage + Any + Send + Sync;
}

#[cfg(feature = "auto-component")]
default impl Component for T {
type Storage = BTreeStorage;
}
```

## Motivation
Often I find myself writing annoying wrappers for structs/enums in other crates. Then afterwards it
takes additional steps to get to the data I care about. This is not a perfect solution, but it does help with quick tests, and small projects where memory efficiency and performance can be overlooked for ease of use.

## Drawbacks
* This feature requires nightly to work.
* It encourages not explicitly implementing `Component` for new components.

If this is something that other people want, I can write a quick pull request for it.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.