Add iterators for nsStyleAutoArray

This commit is contained in:
Manish Goregaokar 2016-06-24 16:39:44 +05:30
parent b1a3831bf6
commit 3a5a56807a
2 changed files with 22 additions and 0 deletions

View file

@ -2,4 +2,5 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
mod ns_style_auto_array;
mod ns_t_array;

View file

@ -0,0 +1,21 @@
use std::iter::{once, Chain, Once, IntoIterator};
use std::slice::{IterMut};
use structs::nsStyleAutoArray;
impl<T> nsStyleAutoArray<T> {
pub fn iter_mut(&mut self) -> Chain<Once<&mut T>, IterMut<T>> {
once(&mut self.mFirstElement).chain(self.mOtherElements.iter_mut())
}
pub fn len(&self) -> usize {
1 + self.mOtherElements.len()
}
}
impl<'a, T> IntoIterator for &'a mut nsStyleAutoArray<T> {
type Item = &'a mut T;
type IntoIter = Chain<Once<&'a mut T>, IterMut<'a, T>>;
fn into_iter(self) -> Self::IntoIter {
self.iter_mut()
}
}