amethyst / amethyst/specs

Default Component Impl

Offen
#640 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
feature-request
Vorherrschende Sprache
Rust
Sterne
2.6k
Forks
215
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

## 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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.