diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index 54d384afc9..2cc53bf92d 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -742,7 +742,7 @@ git_enum! { } pub type git_treewalk_cb = - *const extern "C" fn(*const c_char, *const git_tree_entry, *mut c_void) -> c_int; + extern "C" fn(*const c_char, *const git_tree_entry, *mut c_void) -> c_int; pub type git_treebuilder_filter_cb = Option c_int>; diff --git a/src/call.rs b/src/call.rs index 57aaa26dbd..a18f05da91 100644 --- a/src/call.rs +++ b/src/call.rs @@ -116,17 +116,6 @@ mod impls { } } - impl Convert for crate::TreeWalkMode { - #[cfg(target_env = "msvc")] - fn convert(&self) -> raw::git_treewalk_mode { - *self as i32 - } - #[cfg(not(target_env = "msvc"))] - fn convert(&self) -> raw::git_treewalk_mode { - *self as u32 - } - } - impl Convert for Direction { fn convert(&self) -> raw::git_direction { match *self { diff --git a/src/tree.rs b/src/tree.rs index 376ca9aa2d..3aa2788478 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -61,6 +61,17 @@ impl Into for TreeWalkResult { } } +impl Into for TreeWalkMode { + #[cfg(target_env = "msvc")] + fn into(self) -> raw::git_treewalk_mode { + self as i32 + } + #[cfg(not(target_env = "msvc"))] + fn into(self) -> raw::git_treewalk_mode { + self as u32 + } +} + impl<'repo> Tree<'repo> { /// Get the id (SHA1) of a repository object pub fn id(&self) -> Oid { @@ -118,8 +129,8 @@ impl<'repo> Tree<'repo> { }; try_call!(raw::git_tree_walk( self.raw(), - mode, - treewalk_cb:: as raw::git_treewalk_cb, + mode as raw::git_treewalk_mode, + treewalk_cb::, &mut data as *mut _ as *mut c_void )); Ok(()) @@ -600,7 +611,7 @@ mod tests { let target = head.target().unwrap(); let commit = repo.find_commit(target).unwrap(); let tree = repo.find_tree(commit.tree_id()).unwrap(); - - assert!(tree.walk(TreeWalkMode::PreOrder, |_, _| { -1 }).is_err()); + let e = tree.walk(TreeWalkMode::PreOrder, |_, _| { -1 }).unwrap_err(); + assert_eq!(e.class(), crate::ErrorClass::Callback); } }