Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use impl Trait syntax for Node::child_elements #12854

Merged
merged 1 commit into from Aug 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 5 additions & 9 deletions components/script/dom/node.rs
Expand Up @@ -70,7 +70,7 @@ use std::borrow::ToOwned;
use std::cell::{Cell, UnsafeCell};
use std::cmp::max;
use std::default::Default;
use std::iter::{self, FilterMap, Peekable};
use std::iter;
use std::mem;
use std::ops::Range;
use string_cache::{Atom, Namespace, QualName};
Expand Down Expand Up @@ -781,7 +781,7 @@ impl Node {
}
}

pub fn child_elements(&self) -> ChildElementIterator {
pub fn child_elements(&self) -> impl Iterator<Item=Root<Element>> {
self.children().filter_map(Root::downcast as fn(_) -> _).peekable()
}

Expand Down Expand Up @@ -1111,10 +1111,6 @@ impl LayoutNodeHelpers for LayoutJS<Node> {
// Iteration and traversal
//

pub type ChildElementIterator =
Peekable<FilterMap<NodeSiblingIterator,
fn(Root<Node>) -> Option<Root<Element>>>>;

pub struct NodeSiblingIterator {
current: Option<Root<Node>>,
}
Expand Down Expand Up @@ -1460,7 +1456,7 @@ impl Node {
0 => (),
// Step 6.1.2
1 => {
if !parent.child_elements().peek().is_none() {
if !parent.child_elements().next().is_none() {
return Err(Error::HierarchyRequest);
}
if let Some(child) = child {
Expand All @@ -1476,7 +1472,7 @@ impl Node {
},
// Step 6.2
NodeTypeId::Element(_) => {
if !parent.child_elements().peek().is_none() {
if !parent.child_elements().next().is_none() {
return Err(Error::HierarchyRequest);
}
if let Some(ref child) = child {
Expand All @@ -1503,7 +1499,7 @@ impl Node {
}
},
None => {
if !parent.child_elements().peek().is_none() {
if !parent.child_elements().next().is_none() {
return Err(Error::HierarchyRequest);
}
},
Expand Down
1 change: 1 addition & 0 deletions components/script/lib.rs
Expand Up @@ -5,6 +5,7 @@
#![feature(as_unsafe_cell)]
#![feature(borrow_state)]
#![feature(box_syntax)]
#![feature(conservative_impl_trait)]
#![feature(const_fn)]
#![feature(core_intrinsics)]
#![feature(custom_attribute)]
Expand Down