diff options
author | Hiroyuki Ikezoe <hiikezoe@mozilla-japan.org> | 2017-01-06 19:51:20 +0900 |
---|---|---|
committer | Hiroyuki Ikezoe <hikezoe@mozilla.com> | 2017-01-10 12:24:59 +0900 |
commit | dc3b4803d1469650614a9bf8483ef9d3aaba2a6c (patch) | |
tree | deed164513371eebca998010556e422e34073fa0 | |
parent | 00b3dda3e57b40fc765d4aaa73e9ff200e389c07 (diff) | |
download | servo-dc3b4803d1469650614a9bf8483ef9d3aaba2a6c.tar.gz servo-dc3b4803d1469650614a9bf8483ef9d3aaba2a6c.zip |
Implement Index for nsStyleAutoArray. r=heycam
-rw-r--r-- | components/style/gecko_bindings/sugar/ns_style_auto_array.rs | 14 |
1 files changed, 14 insertions, 0 deletions
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<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> nsStyleAutoArray<T> { /// Mutably iterate over the array elements. pub fn iter_mut(&mut self) -> Chain<Once<&mut T>, IterMut<T>> { |