mirror of
https://github.com/servo/servo.git
synced 2025-07-10 08:53:41 +01:00
Implement Index for nsStyleAutoArray. r=heycam
This commit is contained in:
parent
00b3dda3e5
commit
dc3b4803d1
1 changed files with 14 additions and 0 deletions
|
@ -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>> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue