Skip to content

Default Component Impl #640

@jmeggitt

Description

@jmeggitt

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.

#![cfg_attr(feature = "auto-component", feature(specialization))]

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

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

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions