Skip to content

Commit 760c71d

Browse files
committed
syntax: Add an each_view_item method on traits
1 parent 231aea6 commit 760c71d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libsyntax/ast_util.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,21 @@ pub fn walk_pat(pat: @pat, it: &fn(@pat) -> bool) -> bool {
560560
}
561561
}
562562

563+
pub trait EachViewItem {
564+
pub fn each_view_item(&self, f: @fn(@ast::view_item) -> bool) -> bool;
565+
}
566+
567+
impl EachViewItem for ast::crate {
568+
fn each_view_item(&self, f: @fn(@ast::view_item) -> bool) -> bool {
569+
let broke = @mut false;
570+
let vtor: visit::vt<()> = visit::mk_simple_visitor(@visit::SimpleVisitor {
571+
visit_view_item: |vi| { *broke = f(vi); }, ..*visit::default_simple_visitor()
572+
});
573+
visit::visit_crate(self, (), vtor);
574+
true
575+
}
576+
}
577+
563578
pub fn view_path_id(p: @view_path) -> node_id {
564579
match p.node {
565580
view_path_simple(_, _, id) |

0 commit comments

Comments
 (0)