I'd posted this question on SO and got directed here. I'll reshare it here to foster some discussion.
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.
Anyone one else who thinks this is a cool and would want to use it?
This looks feasible to me. Are there any seriously challenges in implementing something like this?
To extend the discussion, suppose there was a way to find this. I'm not sure where it would fit -
-
Cargo docs sounds like a good place because it's where the documentation lives where I'd typically learn about what traits a particular generic type needs. So getting candidate implementors right there would be great.
-
It could also be a cli command like to query a set of candidates implementors for a set of traits in the context of project.
-
Finally it could also be an extension for something like rust analyzer i.e. a language server