diff options
author | Aurélien Normand <inognitas@bitbucket.org> | 2016-11-01 15:33:50 +0100 |
---|---|---|
committer | Aurélien Normand <inognitas@bitbucket.org> | 2016-11-01 15:33:50 +0100 |
commit | 40da2112d0682143d1b083c461023446375f7326 (patch) | |
tree | 796b9515e8a1c76671cf9999ac4ae07f315265d7 | |
parent | 54d87d37f3eb2f1a19fc53b8c92558417a27d47e (diff) |
Fix #121: Cursor::num_template_args(...) returns Option<u32> instead of c_int
-rwxr-xr-x | src/clang.rs | 14 |
1 files 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<u32> { + 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 |