mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Use impl DoubleEndedIterator for two flow_list iterators
This commit is contained in:
parent
8419f96dc0
commit
a1af2cded8
3 changed files with 7 additions and 30 deletions
|
@ -13,10 +13,6 @@ pub struct FlowList {
|
|||
flows: LinkedList<FlowRef>,
|
||||
}
|
||||
|
||||
pub struct FlowListIterator<'a> {
|
||||
it: linked_list::Iter<'a, FlowRef>,
|
||||
}
|
||||
|
||||
pub struct MutFlowListIterator<'a> {
|
||||
it: linked_list::IterMut<'a, FlowRef>,
|
||||
}
|
||||
|
@ -58,10 +54,8 @@ impl FlowList {
|
|||
|
||||
/// Provide a forward iterator
|
||||
#[inline]
|
||||
pub fn iter(&self) -> FlowListIterator {
|
||||
FlowListIterator {
|
||||
it: self.flows.iter(),
|
||||
}
|
||||
pub fn iter<'a>(&'a self) -> impl DoubleEndedIterator<Item = &'a Flow> {
|
||||
self.flows.iter().map(|flow| &**flow)
|
||||
}
|
||||
|
||||
/// Provide a forward iterator with mutable references
|
||||
|
@ -74,7 +68,8 @@ impl FlowList {
|
|||
|
||||
/// Provide a forward iterator with FlowRef items
|
||||
#[inline]
|
||||
pub fn iter_flow_ref_mut<'a>(&'a mut self) -> linked_list::IterMut<'a, FlowRef> {
|
||||
pub fn iter_flow_ref_mut<'a>(&'a mut self)
|
||||
-> impl DoubleEndedIterator<Item = &'a mut FlowRef> {
|
||||
self.flows.iter_mut()
|
||||
}
|
||||
|
||||
|
@ -98,25 +93,6 @@ impl FlowList {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for FlowListIterator<'a> {
|
||||
type Item = &'a Flow;
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<&'a Flow> {
|
||||
self.it.next().map(|x| &**x)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.it.size_hint()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DoubleEndedIterator for FlowListIterator<'a> {
|
||||
fn next_back(&mut self) -> Option<&'a Flow> {
|
||||
self.it.next_back().map(|x| &**x)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DoubleEndedIterator for MutFlowListIterator<'a> {
|
||||
fn next_back(&mut self) -> Option<&'a mut Flow> {
|
||||
self.it.next_back().map(flow_ref::deref_mut)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue