From 40da2112d0682143d1b083c461023446375f7326 Mon Sep 17 00:00:00 2001 From: Aurélien Normand Date: Tue, 1 Nov 2016 15:33:50 +0100 Subject: Fix #121: Cursor::num_template_args(...) returns Option instead of c_int --- src/clang.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 07680367..c7b3c223 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -130,9 +130,14 @@ impl Cursor { /// Return the number of template arguments used by this cursor's referent, /// if the referent is either a template specialization or /// declaration. Returns -1 otherwise. - pub fn num_template_args(&self) -> c_int { - unsafe { - clang_Cursor_getNumTemplateArguments(self.x) + pub fn num_template_args(&self) -> Option { + let n : c_int = unsafe { clang_Cursor_getNumTemplateArguments(self.x) }; + + if n >= 0 { + Some(n as u32) + } else { + debug_assert_eq!(n, -1); + None } } @@ -192,7 +197,8 @@ impl Cursor { /// Is the referent a fully specialized template specialization without any /// remaining free template arguments? pub fn is_fully_specialized_template(&self) -> bool { - self.is_template() && self.num_template_args() > 0 + self.is_template() && self.num_template_args() + .expect("Not a class template specialization") > 0 } /// Is the referent a template specialization that still has remaining free -- cgit v1.2.3 From 664786a4ed877973c250141790a6a1f6a94ba9f3 Mon Sep 17 00:00:00 2001 From: Aurélien Normand Date: Tue, 1 Nov 2016 16:08:08 +0100 Subject: Fix #121: call unwrap() directly instead of calling except() --- src/clang.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index c7b3c223..ba6fc7f6 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -197,8 +197,7 @@ impl Cursor { /// Is the referent a fully specialized template specialization without any /// remaining free template arguments? pub fn is_fully_specialized_template(&self) -> bool { - self.is_template() && self.num_template_args() - .expect("Not a class template specialization") > 0 + self.is_template() && self.num_template_args().unwrap() > 0 } /// Is the referent a template specialization that still has remaining free -- cgit v1.2.3