1
use forms::{Form, FormValues, drop_orphans};
2

            
3
/// Copies the nested rows fields `form` has from `from` into `to`, keeping a
4
/// present empty field present and a missing one missing, then drops the rows
5
/// whose parent row is not in `to`.
6
180
pub fn copy_carried(form: &Form, from: &FormValues, to: &mut FormValues) {
7
180
    copy_rows(form, from, to);
8
180
    drop_orphans(form, to);
9
180
}
10

            
11
180
fn copy_rows(form: &Form, from: &FormValues, to: &mut FormValues) {
12
180
    for key in form.nested_keys() {
13
100
        let Some(rows) = from.rows(key) else {
14
10
            continue;
15
        };
16
90
        to.set_rows(key);
17
151
        rows.iter().for_each(|row| to.push_row(key, row.clone()));
18
    }
19
180
}