From dc3b4803d1469650614a9bf8483ef9d3aaba2a6c Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Fri, 6 Jan 2017 19:51:20 +0900 Subject: [PATCH] Implement Index for nsStyleAutoArray. r=heycam --- .../gecko_bindings/sugar/ns_style_auto_array.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 5730382d7d1..4ef12625d2d 100644 --- a/components/style/gecko_bindings/sugar/ns_style_auto_array.rs +++ b/components/style/gecko_bindings/sugar/ns_style_auto_array.rs @@ -6,8 +6,22 @@ use gecko_bindings::structs::nsStyleAutoArray; use std::iter::{once, Chain, Once, IntoIterator}; +use std::ops::Index; use std::slice::{Iter, IterMut}; +impl Index for nsStyleAutoArray { + 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 nsStyleAutoArray { /// Mutably iterate over the array elements. pub fn iter_mut(&mut self) -> Chain, IterMut> {