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.

twitu
  • 553
  • 6
  • 12
  • 4
    I doubt something like this exists, but it's a good idea. You might consider starting a thread on https://internals.rust-lang.org/ to propose it as a feature and see what the folks who work on Rust think about it. – Jimmy Sep 17 '22 at 06:38
  • I posted this [question on internals](https://internals.rust-lang.org/t/tool-for-finding-struct-that-implements-a-set-of-traits/17398?u=twitu). It turns out that there is a project under development for trait resolution and queries. Take a look at [chalk](https://github.com/rust-lang/chalk). – twitu Sep 26 '22 at 03:06

0 Answers0