anymap icon indicating copy to clipboard operation
anymap copied to clipboard

How to actually use this

Open Binero opened this issue 7 years ago • 4 comments

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

Binero avatar Feb 05 '17 20:02 Binero

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?

chris-morgan avatar Feb 06 '17 04:02 chris-morgan

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.

Binero avatar Feb 06 '17 13:02 Binero

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

fletching avatar Feb 19 '21 18:02 fletching

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

epage avatar Apr 02 '22 01:04 epage