aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_tt
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_tt')
-rw-r--r--crates/ra_tt/src/lib.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs
index 0b0b9b4d2..9cc646140 100644
--- a/crates/ra_tt/src/lib.rs
+++ b/crates/ra_tt/src/lib.rs
@@ -149,3 +149,15 @@ impl fmt::Display for Punct {
149 fmt::Display::fmt(&self.char, f) 149 fmt::Display::fmt(&self.char, f)
150 } 150 }
151} 151}
152
153impl Subtree {
154 /// Count the number of tokens recursively
155 pub fn count(&self) -> usize {
156 self.token_trees.iter().fold(self.token_trees.len(), |acc, c| {
157 acc + match c {
158 TokenTree::Subtree(c) => c.count(),
159 _ => 0,
160 }
161 })
162 }
163}