rust_struct_iterable
rust_struct_iterable copied to clipboard
Adding `iter_mut` method to Iterable
I'll have a PR out for this is a minute, but it seems to work. Is there some reason this wasn't already implemented? It seems fairly straightforward.
I added the following method signature to the Iterable trait:
fn iter_mut(&mut self) -> std::vec::IntoIter<(&'static str, &'_ mut dyn std::any::Any)>;
Added another field map in the proc macro:
let fields_iter_mut = fields.iter().map(|field| {
let field_ident = &field.ident;
let field_name = field_ident.as_ref().unwrap().to_string();
quote! {
(#field_name, &mut (self.#field_ident) as &mut dyn std::any::Any)
}
});
And constructed the new function:
fn iter_mut<'a>(&'a mut self) -> std::vec::IntoIter<(&'static str, &'a mut dyn std::any::Any)> {
vec![
#(#fields_iter_mut),*
].into_iter()
}
Hi Michael, thank you so much for your PR, I'll check as soon as possible. :)
No problem, and no rush.