subspace icon indicating copy to clipboard operation
subspace copied to clipboard

Opaque<T> that can be converted to/from Vec<T>

Open danakj opened this issue 2 years ago • 2 comments

From @noncombatant:

An opaque sequence type. For example, we often see IPC interfaces where the type is vector, and we say, "Whoa, are you going to parse this?" And the developer says, "No, we never look at it. We just pass it to someone else." Well, it'd be nice to encode that in a type, maybe? E.g. a vector-like thing that has only size method, no operator[]. So you can't parse it, you really can only pass it to someone else (and they can have a Foo::FromOpaque(T&) function)

danakj avatar Dec 20 '22 21:12 danakj

Vec can impl From<Opaque> and Opaque can impl From<Vec>, so you can just into() them.

This puts the contract of "I don't use this" into the type system, instead of just in comments, which is a Good Thing.

danakj avatar Dec 20 '22 21:12 danakj

It could also be a higher level chrome-thing instead of a sus thing, but if we can support into() in that mode. I need to verify we can, I think there's currently no way to have Opaque impl Into<Vec> without Vec's participation.

danakj avatar Dec 20 '22 21:12 danakj