Convenience function to construct an array from an iter of `Datum`s. Returns an error if the number of elements in `iter` does not match the cardinality of the array as described by `dims`, or if the number of dimensions exceeds [`MAX_ARRAY_DIMENSIONS`]. If an error occurs, the packer's state will be unchanged.
(
&mut self,
dims: &[ArrayDimension],
iter: I,
)
| 2441 | /// number of dimensions exceeds [`MAX_ARRAY_DIMENSIONS`]. If an error |
| 2442 | /// occurs, the packer's state will be unchanged. |
| 2443 | pub fn try_push_array<'a, I, D>( |
| 2444 | &mut self, |
| 2445 | dims: &[ArrayDimension], |
| 2446 | iter: I, |
| 2447 | ) -> Result<(), InvalidArrayError> |
| 2448 | where |
| 2449 | I: IntoIterator<Item = D>, |
| 2450 | D: Borrow<Datum<'a>>, |
| 2451 | { |
| 2452 | // SAFETY: The function returns the exact number of elements pushed into the array. |
| 2453 | unsafe { |
| 2454 | self.push_array_with_unchecked(dims, |packer| { |
| 2455 | let mut nelements = 0; |
| 2456 | for datum in iter { |
| 2457 | packer.push(datum); |
| 2458 | nelements += 1; |
| 2459 | } |
| 2460 | Ok::<_, InvalidArrayError>(nelements) |
| 2461 | }) |
| 2462 | } |
| 2463 | } |
| 2464 | |
| 2465 | /// Like [`RowPacker::try_push_array`], but accepts a fallible iterator of |
| 2466 | /// elements. |