use crate::Array; use super::List; /// A helper method that implements apply_list for you pub fn apply_list(apply_to: &mut dyn List, other: &dyn List) { assert_eq!(apply_to.len(), other.len(), "Lists must be the same length when applying one to the other!"); let len = apply_to.len(); for i in 0..len { let el = apply_to.get_mut(i).unwrap(); el.apply(other.get(i).unwrap()); } } pub fn apply_array(apply_to: &mut dyn Array, other: &dyn Array) { assert_eq!(apply_to.len(), other.len(), "Arrays must be the same length when applying one to the other!"); let len = apply_to.len(); for i in 0..len { let el = apply_to.get_mut(i).unwrap(); el.apply(other.get(i).unwrap()); } } /// A helper method that implements [`Reflect::clone_inner`] for you. pub fn clone_inner_list(clone: &dyn List) -> Box { let mut empty = clone.create_empty(); empty.reserve(clone.len()); for i in 0..clone.len() { let el = clone.get(i).unwrap(); let el_clone = el.clone_inner(); // ignore failures, they shouldn't happen since `empty` was cloned from // `clone`, so they're the same type. let _ = empty.push_back(el_clone); } empty }