chris-morgan / anymap

A safe and convenient store for one value of each type
Other
326 stars 42 forks source link

How to actually use this #29

Open Binero opened 7 years ago

Binero commented 7 years ago

I want to crate a Map<Component>, but whatever I do, Rust always says error[E0277]: the trait bound `Component + 'static: anymap::any::UncheckedAnyExt` is not satisfied.

I have tried so much now:

pub trait Component {
pub trait Component: std::any::Any {
pub trait Component: anymap::any::Any {
pub trait Component: anymap::any::Any + anymap::any::UncheckedAnyExt {
pub trait Component: 'static + anymap::any::Any + anymap::any::UncheckedAnyExt {
pub trait Component: 'static + std::any::Any + anymap::any::Any + anymap::any::UncheckedAnyExt {

I am lost on what to do...

chris-morgan commented 7 years ago

Map is generic specifically for the Clone and concurrency features; the types that are designed to slot in there are Any, Any + Send + Sync, CloneAny, &c., with the full list of all eight here.

I’ve thought about making it compatible with custom Any types—such as with mopa—but that would be a rather substantial change to the approach employed, and I haven’t seen any evidence that people would gain benefit from it. Would you?

Binero commented 7 years ago

It would very much help given I only want to allow types implementing Component into the map. That said, if it's outside of the scope of this crate, I am fine with implementing it myself, of course.

fletching commented 3 years ago

@Binero I know this was ages ago, but do you have an implementation you could share? I have the same sort of need.

epage commented 2 years ago

I had assumed this was possible and was planning clap around it. My plan for clap was to have multiple anymap's and wanted them to be typed so people can only use types designed for each one.

See https://github.com/clap-rs/clap/discussions/3476 for more details on my thoughts for clap.

I believe I'll also need IntoBox public so I can provide my own getters / setters since I won't be directly exposing the anymap