다른 사람이 만든 제네릭 API를 감싸는 래퍼를 만들고 있는데, 이 API의 FromEncoding 트레이트는 대부분의 기본 타입을 지원해요[1] (#footnote-682731-1). 이 API가 내놓는 값들을 컬렉션에 모으는 기능을 래퍼에 넣고 싶어요.
처음에는 “컬렉션이 FromIterator<Element>를 구현하니까 그걸 쓰면 되지 않을까?”라고 생각했어요. 그런데 Rust가 제가 어떤 Element를 뜻하는지 알아내지 못하네요. 여러 impl FromEncoding for IterElement가 각각 impl FromIterator<IterElement> for Bucket<BucketElement>에 해당할 수 있으니 충분히 이해는 가요. 이걸 해결할 방법이 있을까요, 아니면 지원하는 컬렉션을 몇 가지, 예를 들어 Vec와 HashSet로 제한해야 할까요?
XY 문제인지 판단하는 데 도움이 될까 해서 덧붙이면, 실제 트레이트는 rusqlite::FromSql예요. ↩︎ (#footnote-ref-682731-1)
영어에서 번역·원문 보기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)