BrainTeaser: Filter for a type in collection of enums

Hi there, I've got a type-level question, where I would like to build a nice API, but don't know how to.
Maybe it's not even possible :man_shrugging:

I have a Vec<SomeEnum> and each variant contains another type. Now I'd like to be able to filter by type somehow so tat I can say my_vec.get::<Thing> and I get a Vec of just the Things in there.

see playground

Is that even possible? Is there maybe already a crate that does this? Am I just overslept and there is a trivial other way of doing this?

Thanks a bunch and happy holidays everybody!

All you need is to crate a trait which Ball, Die, and Rope need to implement. I'll try to extend the example accordingly.

For example: Rust Playground

2 Likes

Oh nice, that looks very much like it!

Vielen lieben Dank :+1:

1 Like

I hadn't considered macros for the solution either

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.