2024-01-06 20:52:12 +00:00
|
|
|
use crate::Array;
|
|
|
|
|
2023-12-30 23:55:05 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-06 20:52:12 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-30 23:55:05 +00:00
|
|
|
/// A helper method that implements [`Reflect::clone_inner`] for you.
|
|
|
|
pub fn clone_inner_list(clone: &dyn List) -> Box<dyn List> {
|
|
|
|
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
|
|
|
|
}
|