Implement Index for nsStyleAutoArray. r=heycam

This commit is contained in:
Hiroyuki Ikezoe 2017-01-06 19:51:20 +09:00 committed by Hiroyuki Ikezoe
parent 00b3dda3e5
commit dc3b4803d1

View file

@ -6,8 +6,22 @@
use gecko_bindings::structs::nsStyleAutoArray; use gecko_bindings::structs::nsStyleAutoArray;
use std::iter::{once, Chain, Once, IntoIterator}; use std::iter::{once, Chain, Once, IntoIterator};
use std::ops::Index;
use std::slice::{Iter, IterMut}; 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> { impl<T> nsStyleAutoArray<T> {
/// Mutably iterate over the array elements. /// Mutably iterate over the array elements.
pub fn iter_mut(&mut self) -> Chain<Once<&mut T>, IterMut<T>> { pub fn iter_mut(&mut self) -> Chain<Once<&mut T>, IterMut<T>> {