openlang

Finding the item behind an impl FromIterator

I'm building a wrapper for somebody else's generic API, whose FromEncoding trait supports most primitive types[1] (#footnote-682731-1). I want this wrapper to support gathering the values supplied by that API together into a collection.

Initially I thought, "collections implement FromIterator<Element>, couldn't that handle it?" Apparently not, since Rust (quite reasonably) can't determine which Element I mean: several impl FromEncoding for IterElement could each match an impl FromIterator<IterElement> for Bucket<BucketElement>. Is there a way around this, or should I just support a fixed selection of collections (say Vec and HashSet)?

The actual trait here is rusqlite::FromSql, if that helps rule out an XY problem. ↩︎ (#footnote-ref-682731-1)

The conversation continues 2

Follow the reasoning
  1. Permalink

    Could you share a small example that fails, together with the compiler's diagnostic? I can't quite tell which constraints you're trying to express on these types. Seeing the attempt that the compiler refused would give us a much clearer starting point for working out a solution.

Other sides of the same question

  1. How can I subclass a class inside another class?

    Hi, In a package whose code is outside my control, there is a hierarchy of classes arranged as follows: I'm trying to add a w…

    Replies 1Latest activity scala
  2. Comparing have with let bindings in Lean4

    I've observed that these two expressions and behave identically. This also happens in theorem proofs. Are they interchangeabl…

    Replies 3Latest activity lean-4
  3. TypeScript Map initialization with string array entries

    I'm creating a Map whose entries each hold an array of strings. How can I declare its type and initialize it together in one…

    Replies 2Latest activity typescript