Bug 1330824 - Add IndexMut for nsStyleAutoArray. r?heycam draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Sat, 14 Jan 2017 08:14:33 +0900
changeset 460844 aa2180dc2eb0c13bd5730f00d4c3233646ee1f3d
parent 460843 c77069e7441d6c05958882351e58a55596fb6ed3
child 460845 76c18191cab316a055e8b0d49ba7b6fd4c8541a9
push id41514
push userhiikezoe@mozilla-japan.org
push dateFri, 13 Jan 2017 23:27:08 +0000
reviewersheycam
bugs1330824
milestone53.0a1
Bug 1330824 - Add IndexMut for nsStyleAutoArray. r?heycam MozReview-Commit-ID: 9EU8g4SLoHp
servo/components/style/gecko_bindings/sugar/ns_style_auto_array.rs
--- a/servo/components/style/gecko_bindings/sugar/ns_style_auto_array.rs
+++ b/servo/components/style/gecko_bindings/sugar/ns_style_auto_array.rs
@@ -2,32 +2,44 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! Rust helpers for Gecko's `nsStyleAutoArray`.
 
 use gecko_bindings::bindings::Gecko_EnsureStyleAnimationArrayLength;
 use gecko_bindings::structs::nsStyleAutoArray;
 use std::iter::{once, Chain, Once, IntoIterator};
-use std::ops::Index;
+use std::ops::{Index, IndexMut};
 use std::slice::{Iter, IterMut};
 
 impl<T> Index<usize> for nsStyleAutoArray<T> {
     type Output = T;
     fn index(&self, index: usize) -> &T {
         if index > self.len() {
             panic!("out of range")
         }
         match index {
             0 => &self.mFirstElement,
             _ => &self.mOtherElements[index - 1],
         }
     }
 }
 
+impl<T> IndexMut<usize> for nsStyleAutoArray<T> {
+    fn index_mut(&mut self, index: usize) -> &mut T {
+        if index > self.len() {
+            panic!("out of range")
+        }
+        match index {
+            0 => &mut self.mFirstElement,
+            _ => &mut self.mOtherElements[index - 1],
+        }
+    }
+}
+
 impl<T> nsStyleAutoArray<T> {
     /// Mutably iterate over the array elements.
     pub fn iter_mut(&mut self) -> Chain<Once<&mut T>, IterMut<T>> {
         once(&mut self.mFirstElement).chain(self.mOtherElements.iter_mut())
     }
 
     /// Iterate over the array elements.
     pub fn iter(&self) -> Chain<Once<&T>, Iter<T>> {