Skip to main content

cli_core/forms/
carried.rs

1use 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`.
6pub fn copy_carried(form: &Form, from: &FormValues, to: &mut FormValues) {
7    copy_rows(form, from, to);
8    drop_orphans(form, to);
9}
10
11fn copy_rows(form: &Form, from: &FormValues, to: &mut FormValues) {
12    for key in form.nested_keys() {
13        let Some(rows) = from.rows(key) else {
14            continue;
15        };
16        to.set_rows(key);
17        rows.iter().for_each(|row| to.push_row(key, row.clone()));
18    }
19}