diff options
Diffstat (limited to 'crates/ra_tt')
-rw-r--r-- | crates/ra_tt/src/lib.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index 0b0b9b4d2..62c5ac52a 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs | |||
@@ -149,3 +149,19 @@ impl fmt::Display for Punct { | |||
149 | fmt::Display::fmt(&self.char, f) | 149 | fmt::Display::fmt(&self.char, f) |
150 | } | 150 | } |
151 | } | 151 | } |
152 | |||
153 | impl Subtree { | ||
154 | /// Count the number of tokens recursively | ||
155 | pub fn count(&self) -> usize { | ||
156 | let children_count = self | ||
157 | .token_trees | ||
158 | .iter() | ||
159 | .map(|c| match c { | ||
160 | TokenTree::Subtree(c) => c.count(), | ||
161 | _ => 0, | ||
162 | }) | ||
163 | .sum::<usize>(); | ||
164 | |||
165 | self.token_trees.len() + children_count | ||
166 | } | ||
167 | } | ||