Closed jonhoo closed 8 years ago
As a heads up, rust-postgres
natively supports conversions of one dimensional postgres arrays to and from Rust slices and Vec
s since version 0.11.5. This still seems reasonable to add for the multi dimensional case though.
into_inner
is a more common name for this kind of conversion - could you renamve extract
to that? Looks good other than that though, thanks!
Oh, neat! I can't find any mention of that in the rust-postgres
readme beyond [u8] <-> BYTEA
?
into_inner
is a better name, you're right.
That's because I forgot to mention it in the table in the readme, will fix :). It is mentioned in the docs for FromSql and ToSql though: http://sfackler.github.io/rust-postgres/doc/v0.11.7/postgres/types/trait.FromSql.html#arrays.
When fetching rows with
rust-postgres
, turning a Postgres Array from a returned row into a Rust Vec is not quite straightforward, and requirings going to anIntoIterator
and back:This adds overhead, and could even add an allocation in the worst case. A better solution would be to provide a method for directly extracting the underlying Vec of a row.
This PR adds
Array::extract()
, which does just that. It consumes theArray
, and returns the underlyingVec
, allowing the code above to be expressed as: