-
Notifications
You must be signed in to change notification settings - Fork 18
Description
(This is indirectly related to #79)
A few examples I was also wondering about, might be worth pondering on - legit collections where direct .collect() just doesn't cut it (along with the current TryIntoCollection logic).
-
Types like
vec1::Vec1<T>(a fairly popular crate for what it does). It can be iterated over but, obviously, doesn't supportFromIteratorbecause it can fail if there's no items. It also can't implementDefaultand you have to provide the first element intonew(first). Serialization is not a problem, but what about deserialization? -
Any constrained collections, e.g. maybe
EvenVec<T: Integer>that has atry_push()which may fail if the integer is not even. Again,FromIteratorcan't be implemented (butDefaultcan be, unlike the previous example).
In both of these examples you would probably have them implement TryFrom<Vec<T>> or TryFrom<&[T]> (or both, depending on whether it uses Vec<T> internally or not) - in fact vec1::Vec1 already implements both.
- So, one way would be to convert/collect elements from arrow into a Vec and then
TryFrom-convert it into your custom collection. I believe this will cover the majority of cases like this. - Another way would be to add support for failures during deserialization (see next example).
In regards to fallible deserialization, there's an even simpler example without containers:
-
struct EvenNumber(i32)with anEvenNumber::try_new(i32) -> Result<Self, Error>fallible constructor. Again, serializing this is fine. But what about deserialization? The current signature returnsdeserialize(...) -> Option<T>which wouldn't support cases like this. -
Similar example, but from standard library - the family of
NonZero{U,I}*types - https://doc.rust-lang.org/stable/std/num/index.html.