From 2d19e67fc49db4b9ee5f56bb2156d2a7fe6e3405 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Sat, 14 Jan 2017 11:39:33 +0900 Subject: [PATCH] Bug 1330824 - Add IndexMut for nsStyleAutoArray. r=heycam MozReview-Commit-ID: 9EU8g4SLoHp --- .../gecko_bindings/sugar/ns_style_auto_array.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/style/gecko_bindings/sugar/ns_style_auto_array.rs b/components/style/gecko_bindings/sugar/ns_style_auto_array.rs index 9c41a0b6ec4..b20ee735631 100644 --- a/components/style/gecko_bindings/sugar/ns_style_auto_array.rs +++ b/components/style/gecko_bindings/sugar/ns_style_auto_array.rs @@ -7,7 +7,7 @@ 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 Index for nsStyleAutoArray { @@ -23,6 +23,18 @@ impl Index for nsStyleAutoArray { } } +impl IndexMut for nsStyleAutoArray { + 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 nsStyleAutoArray { /// Mutably iterate over the array elements. pub fn iter_mut(&mut self) -> Chain, IterMut> {