Add an iter_mut method to Fields
diff --git a/src/data.rs b/src/data.rs
index 3d1924a..8ffc8a4 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -66,9 +66,9 @@
}
impl Fields {
- /// Get an iterator over the [`Field`] items in this object. This iterator
- /// can be used to iterate over a named or unnamed struct or variant's
- /// fields uniformly.
+ /// Get an iterator over the borrowed [`Field`] items in this object. This
+ /// iterator can be used to iterate over a named or unnamed struct or
+ /// variant's fields uniformly.
///
/// [`Field`]: struct.Field.html
pub fn iter(&self) -> punctuated::Iter<Field> {
@@ -78,6 +78,19 @@
Fields::Unnamed(ref f) => f.unnamed.iter(),
}
}
+
+ /// Get an iterator over the mutably borrowed [`Field`] items in this
+ /// object. This iterator can be used to iterate over a named or unnamed
+ /// struct or variant's fields uniformly.
+ ///
+ /// [`Field`]: struct.Field.html
+ pub fn iter_mut(&mut self) -> punctuated::IterMut<Field> {
+ match *self {
+ Fields::Unit => punctuated::IterMut::private_empty(),
+ Fields::Named(ref mut f) => f.named.iter_mut(),
+ Fields::Unnamed(ref mut f) => f.unnamed.iter_mut(),
+ }
+ }
}
impl<'a> IntoIterator for &'a Fields {
@@ -89,6 +102,15 @@
}
}
+impl<'a> IntoIterator for &'a mut Fields {
+ type Item = &'a mut Field;
+ type IntoIter = punctuated::IterMut<'a, Field>;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.iter_mut()
+ }
+}
+
ast_struct! {
/// A field of a struct or enum variant.
///