mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Add iterators for vector types
MozReview-Commit-ID: I7oOpYhVP5S
This commit is contained in:
parent
36f26148e6
commit
c85aae4abd
3 changed files with 43 additions and 3 deletions
|
@ -100,6 +100,35 @@ impl<'a> Context<'a> {
|
|||
pub fn mutate_style(&mut self) -> &mut StyleBuilder<'a> { &mut self.style }
|
||||
}
|
||||
|
||||
/// An iterator over a slice of computed values
|
||||
pub struct ComputedVecIter<'a, 'cx, 'cx_a: 'cx, S: ToComputedValue + 'a> {
|
||||
cx: &'cx Context<'cx_a>,
|
||||
values: &'a [S],
|
||||
}
|
||||
|
||||
impl<'a, 'cx, 'cx_a: 'cx, S: ToComputedValue + 'a> ComputedVecIter<'a, 'cx, 'cx_a, S> {
|
||||
/// Construct an iterator from a slice of specified values and a context
|
||||
pub fn new(cx: &'cx Context<'cx_a>, values: &'a [S]) -> Self {
|
||||
ComputedVecIter {
|
||||
cx: cx,
|
||||
values: values,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'cx, 'cx_a: 'cx, S: ToComputedValue + 'a> Iterator for ComputedVecIter<'a, 'cx, 'cx_a, S> {
|
||||
type Item = S::ComputedValue;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if let Some((next, rest)) = self.values.split_first() {
|
||||
let ret = next.to_computed_value(self.cx);
|
||||
self.values = rest;
|
||||
Some(ret)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A trait to represent the conversion between computed and specified values.
|
||||
pub trait ToComputedValue {
|
||||
/// The computed value type we're going to be converted to.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue