Find structs that implement a given set of traits
Asked Answered
J

0

6

I've come across a case where I have a generic that needs to satisfy two traits.

pub struct FileReader<R: Read + Seek> { /* private fields */ }

These are standard traits and I can find their implementors individually. Then I can see which implementors are common and use one of them.

However this made me consider if there's a way to query - cargo docs, the compiler or something to find possible structs that implement a given set of traits. This might be useful when generics have many trait conditions and/or a trait has many implementors.

Cargo docs already has a search bar for queries but it's for searching with names or with function types. Not one level up queries like these.

Jarman answered 17/9, 2022 at 5:26 Comment(2)
I doubt something like this exists, but it's a good idea. You might consider starting a thread on internals.rust-lang.org to propose it as a feature and see what the folks who work on Rust think about it.Pavlov
I posted this question on internals. It turns out that there is a project under development for trait resolution and queries. Take a look at chalk.Jarman

© 2022 - 2024 — McMap. All rights reserved.