Implement nsStyleAutoArray.ensure_len(). r?heycam
draft
Implement nsStyleAutoArray.ensure_len(). r?heycam
MozReview-Commit-ID: 9MvW5DcscSD
--- a/servo/components/style/gecko_bindings/sugar/ns_style_auto_array.rs
+++ b/servo/components/style/gecko_bindings/sugar/ns_style_auto_array.rs
@@ -1,12 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
+use gecko_bindings::bindings::Gecko_EnsureStyleAnimationArrayLength;
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 {
@@ -29,16 +30,23 @@ impl<T> nsStyleAutoArray<T> {
}
// Note that often structs containing autoarrays will have
// additional member fields that contain the length, which must be kept
// in sync
pub fn len(&self) -> usize {
1 + self.mOtherElements.len()
}
+
+ pub fn ensure_len(&mut self, len: usize) {
+ unsafe {
+ Gecko_EnsureStyleAnimationArrayLength(self as *mut nsStyleAutoArray<T> as *mut _,
+ 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()
}