From dab11134c2cbf973c9aef83831439e282a9b18c9 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 28 May 2021 12:27:50 -0700 Subject: [PATCH] Add Query::capture_index_for_name method Co-Authored-By: Nathan Sobo --- lib/binding_rust/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index 2cf5898e..d187c965 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -1512,6 +1512,14 @@ impl Query { &self.capture_names } + /// Get the index for a given capture name. + pub fn capture_index_for_name(&self, name: &str) -> Option { + self.capture_names + .iter() + .position(|n| n == name) + .map(|ix| ix as u32) + } + /// Get the properties that are checked for the given pattern index. /// /// This includes predicates with the operators `is?` and `is-not?`.