MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / try_push_array_fallible

Method try_push_array_fallible

src/repr/src/row.rs:2467–2503  ·  view source on GitHub ↗

Like [`RowPacker::try_push_array`], but accepts a fallible iterator of elements.

(
        &mut self,
        dims: &[ArrayDimension],
        iter: I,
    )

Source from the content-addressed store, hash-verified

2465 /// Like [`RowPacker::try_push_array`], but accepts a fallible iterator of
2466 /// elements.
2467 pub fn try_push_array_fallible<'a, I, D, E>(
2468 &mut self,
2469 dims: &[ArrayDimension],
2470 iter: I,
2471 ) -> Result<Result<(), E>, InvalidArrayError>
2472 where
2473 I: IntoIterator<Item = Result<D, E>>,
2474 D: Borrow<Datum<'a>>,
2475 {
2476 enum Error<E> {
2477 Usage(InvalidArrayError),
2478 Inner(E),
2479 }
2480
2481 impl<E> From<InvalidArrayError> for Error<E> {
2482 fn from(e: InvalidArrayError) -> Self {
2483 Self::Usage(e)
2484 }
2485 }
2486
2487 // SAFETY: The function returns the exact number of elements pushed into the array.
2488 let result = unsafe {
2489 self.push_array_with_unchecked(dims, |packer| {
2490 let mut nelements = 0;
2491 for datum in iter {
2492 packer.push(datum.map_err(Error::Inner)?);
2493 nelements += 1;
2494 }
2495 Ok(nelements)
2496 })
2497 };
2498 match result {
2499 Ok(()) => Ok(Ok(())),
2500 Err(Error::Usage(e)) => Err(e),
2501 Err(Error::Inner(e)) => Ok(Err(e)),
2502 }
2503 }
2504
2505 /// Convenience function to construct an array from a function. The function must return the
2506 /// number of elements it pushed into the array. It is undefined behavior if the function returns

Callers 1

into_resultMethod · 0.80

Calls 2

pushMethod · 0.45

Tested by

no test coverage detected