Given an `impl FromIterator`, find item type

I'm trying to wrap an external generic API, which has a FromRepresentation trait implemented for most primitive types[1]. I'd like to add a way for this wrapper to collect items from this API into a collection.

My first idea was "well, every collection is FromIterator<Item>, so can't I simply use that?" But apparently, I can't, because Rust (rightfully) cannot infer the Item I want: there might be multiple impl FromRepresentation for IteratorItem which would all correspond to impl FromIterator<IteratorItem> for Container<ContainerItem>. Could this be done somehow, or would it be better if I restrict myself to a closed list of types (e.g. only Vec and HashSet)?


  1. Specifically, this is rusqlite::FromSql, in case this looks like an XY problem. ↩︎

Can you please include a snippet of the failing code with compiler error message? It's hard to understand exactly what type constraints you want to represent. If you show us what you did, but was rejected by the compiler, it will be easier to find a solution for your problem.

See Obtaining associated constant from `impl Trait` parameter; this seems very similar.