rs_split_table/
split.rs

1//! Functions to copy the rows from the source to the target.
2
3use futures::TryStreamExt;
4
5use tonic::Status;
6
7use crate::source::DataSource;
8use crate::target::DataTarget;
9
10/// Copies the rows got from the source to the target.
11pub async fn copy<S, T>(src: &S, tgt: &T) -> Result<u64, Status>
12where
13    S: DataSource,
14    T: DataTarget<Row = S::Row>,
15{
16    let row_strm = src.get_rows().await?;
17    row_strm
18        .try_fold(0, |state, next| async move {
19            let row: &S::Row = &next;
20            tgt.save(row).await?;
21            Ok(state + 1)
22        })
23        .await
24}