diff options
author | Takanori Ishibashi <takanori.1112@gmail.com> | 2016-11-14 08:26:48 +0900 |
---|---|---|
committer | Takanori Ishibashi <takanori.1112@gmail.com> | 2016-11-14 08:26:48 +0900 |
commit | 76b5372efa95047bc0200067a3f7493b39060a5f (patch) | |
tree | e583959eef4a61f742468423d7e8110c1efdeb04 | |
parent | c9eccea095a77989950410bf2715d59a8af7a1fd (diff) |
Return Option<Cursor> instead of Cursor
-rwxr-xr-x | src/clang.rs | 8 | ||||
-rw-r--r-- | src/ir/ty.rs | 4 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/clang.rs b/src/clang.rs index 12397534..315d87a0 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -263,11 +263,13 @@ impl Cursor { /// Given that this cursor's referent is reference type, get the cursor /// pointing to the referenced type. - pub fn referenced(&self) -> Cursor { + pub fn referenced(&self) -> Option<Cursor> { unsafe { - Cursor { + let ret = Cursor { x: clang_getCursorReferenced(self.x), - } + }; + + if ret.is_valid() { Some(ret) } else { None } } } diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 77dc61be..09961637 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -612,7 +612,7 @@ impl Type { TypeKind::TemplateAlias(inner.unwrap(), args) } CXCursor_TemplateRef => { - let referenced = location.referenced(); + let referenced = location.referenced().expect("expected value, got none"); let referenced_ty = referenced.cur_type(); let referenced_declaration = Some(referenced_ty.declaration()); @@ -624,7 +624,7 @@ impl Type { ctx); } CXCursor_TypeRef => { - let referenced = location.referenced(); + let referenced = location.referenced().expect("expected value, got none"); let referenced_ty = referenced.cur_type(); let referenced_declaration = Some(referenced_ty.declaration()); |