Skip to content

Commit 3ce2f87

Browse files
committed
Simplify some of the tree_walk changes
* I'm pretty sure the fn pointer doesn't need to have `*const`. * No need to move `Convert` around, can just use `as` for an enum (can maybe just remove this impl?). * Verify the actual error in the test.
1 parent 41d8e06 commit 3ce2f87

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

libgit2-sys/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ git_enum! {
742742
}
743743

744744
pub type git_treewalk_cb =
745-
*const extern "C" fn(*const c_char, *const git_tree_entry, *mut c_void) -> c_int;
745+
extern "C" fn(*const c_char, *const git_tree_entry, *mut c_void) -> c_int;
746746
pub type git_treebuilder_filter_cb =
747747
Option<extern "C" fn(*const git_tree_entry, *mut c_void) -> c_int>;
748748

src/call.rs

-11
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,6 @@ mod impls {
116116
}
117117
}
118118

119-
impl Convert<raw::git_treewalk_mode> for crate::TreeWalkMode {
120-
#[cfg(target_env = "msvc")]
121-
fn convert(&self) -> raw::git_treewalk_mode {
122-
*self as i32
123-
}
124-
#[cfg(not(target_env = "msvc"))]
125-
fn convert(&self) -> raw::git_treewalk_mode {
126-
*self as u32
127-
}
128-
}
129-
130119
impl Convert<raw::git_direction> for Direction {
131120
fn convert(&self) -> raw::git_direction {
132121
match *self {

src/tree.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ impl Into<i32> for TreeWalkResult {
6161
}
6262
}
6363

64+
impl Into<raw::git_treewalk_mode> for TreeWalkMode {
65+
#[cfg(target_env = "msvc")]
66+
fn into(self) -> raw::git_treewalk_mode {
67+
self as i32
68+
}
69+
#[cfg(not(target_env = "msvc"))]
70+
fn into(self) -> raw::git_treewalk_mode {
71+
self as u32
72+
}
73+
}
74+
6475
impl<'repo> Tree<'repo> {
6576
/// Get the id (SHA1) of a repository object
6677
pub fn id(&self) -> Oid {
@@ -118,8 +129,8 @@ impl<'repo> Tree<'repo> {
118129
};
119130
try_call!(raw::git_tree_walk(
120131
self.raw(),
121-
mode,
122-
treewalk_cb::<T> as raw::git_treewalk_cb,
132+
mode as raw::git_treewalk_mode,
133+
treewalk_cb::<T>,
123134
&mut data as *mut _ as *mut c_void
124135
));
125136
Ok(())
@@ -600,7 +611,7 @@ mod tests {
600611
let target = head.target().unwrap();
601612
let commit = repo.find_commit(target).unwrap();
602613
let tree = repo.find_tree(commit.tree_id()).unwrap();
603-
604-
assert!(tree.walk(TreeWalkMode::PreOrder, |_, _| { -1 }).is_err());
614+
let e = tree.walk(TreeWalkMode::PreOrder, |_, _| { -1 }).unwrap_err();
615+
assert_eq!(e.class(), crate::ErrorClass::Callback);
605616
}
606617
}

0 commit comments

Comments
 (0)