Skip to content

Commit

Permalink
Implement Index for nsStyleAutoArray. r=heycam
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroyuki Ikezoe authored and Hiroyuki Ikezoe committed Jan 10, 2017
1 parent 00b3dda commit dc3b480
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions components/style/gecko_bindings/sugar/ns_style_auto_array.rs
Expand Up @@ -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>> {
Expand Down

0 comments on commit dc3b480

Please sign in to comment.