style: Document sugar for nsStyleAutoArray.

This commit is contained in:
Emilio Cobos Álvarez 2017-01-02 03:27:27 +01:00
parent 89f3e34f48
commit 1bd246905c
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -2,21 +2,27 @@
* 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/. */
//! Rust helpers for Gecko's `nsStyleAutoArray`.
use gecko_bindings::structs::nsStyleAutoArray;
use std::iter::{once, Chain, Once, IntoIterator};
use std::slice::{Iter, IterMut};
impl<T> nsStyleAutoArray<T> {
/// Mutably iterate over the array elements.
pub fn iter_mut(&mut self) -> Chain<Once<&mut T>, IterMut<T>> {
once(&mut self.mFirstElement).chain(self.mOtherElements.iter_mut())
}
/// Iterate over the array elements.
pub fn iter(&self) -> Chain<Once<&T>, Iter<T>> {
once(&self.mFirstElement).chain(self.mOtherElements.iter())
}
// Note that often structs containing autoarrays will have
// additional member fields that contain the length, which must be kept
// in sync
/// Returns the length of the array.
///
/// 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()
}