Closed ankane closed 1 month ago
It's not safe to put Ruby's Value
type on the heap, so Vec<T>
only implements TryConvert
where T
implements TryConvertOwned
. And TryConvertOwned
is just a promise that your type doesn't contain a Value
.
A unsafe impl TryConvertOwned for MyType {}
should fix your example (as far as getting Vec::<MyType>::try_convert(v)
working).
Vec::<(MyType,)>
should encounter the same error, but I messed up the type bounds for tuples. I'll fix that.
MyType
should be fine to put on the heap, right? (since it shouldn't contain a value?)
Ah, I think I see what you're saying. The code should use unsafe impl TryConvertOwned for MyType {}
if it won't contain a value.
The code should use
unsafe impl TryConvertOwned for MyType {}
if it won't contain a value.
Yep, that's it. TryConvertOwned
is just a marker trait that requires TryConvert
for the actual implementation. Similar to how PartialEq
has the equality implementation, and Eq
is just a promise on top of that that the type is fully equivalent.
Great, thanks @matsadler!
Hi @matsadler, hope you're doing well.
I ran into some unexpected behavior with
try_convert
(but there may be a reason for it).The non-tuple version fails to compile with: