Skip to content

Commit 7be7525

Browse files
committed
Cargo fmt
1 parent 52fc8d0 commit 7be7525

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/tracing.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::{ffi::CStr, sync::atomic::{AtomicPtr, Ordering}};
1+
use std::{
2+
ffi::CStr,
3+
sync::atomic::{AtomicPtr, Ordering},
4+
};
25

36
use libc::{c_char, c_int};
47

@@ -61,18 +64,16 @@ impl Binding for TraceLevel {
6164
/// see `trace_set` to register a subscriber.
6265
pub type TracingCb = fn(TraceLevel, &[u8]);
6366

64-
/// Use an atomic pointer to store the global tracing subscriber function.
67+
/// Use an atomic pointer to store the global tracing subscriber function.
6568
static CALLBACK: AtomicPtr<()> = AtomicPtr::new(std::ptr::null_mut());
6669

6770
/// Set the global subscriber called when libgit2 produces a tracing message.
6871
pub fn trace_set(level: TraceLevel, cb: TracingCb) -> Result<(), Error> {
6972
// Store the callback in the global atomic.
7073
CALLBACK.store(cb as *mut (), Ordering::SeqCst);
7174

72-
// git_trace_set returns 0 if there was no error.
73-
let return_code: c_int = unsafe {
74-
raw::git_trace_set(level.raw(), Some(tracing_cb_c))
75-
};
75+
// git_trace_set returns 0 if there was no error.
76+
let return_code: c_int = unsafe { raw::git_trace_set(level.raw(), Some(tracing_cb_c)) };
7677

7778
if return_code != 0 {
7879
// Unwrap here is fine since `Error::last_error` always returns `Some`.
@@ -88,10 +89,10 @@ extern "C" fn tracing_cb_c(level: raw::git_trace_level_t, msg: *const c_char) {
8889
let cb: *mut () = CALLBACK.load(Ordering::SeqCst);
8990

9091
// Transmute the callback pointer into the function pointer we know it to be.
91-
//
92-
// SAFETY: We only ever set the callback pointer with something cast from a TracingCb
93-
// so transmuting back to a TracingCb is safe. This is notably not an integer-to-pointer
94-
// transmute as described in the mem::transmute documentation and is in-line with the
92+
//
93+
// SAFETY: We only ever set the callback pointer with something cast from a TracingCb
94+
// so transmuting back to a TracingCb is safe. This is notably not an integer-to-pointer
95+
// transmute as described in the mem::transmute documentation and is in-line with the
9596
// example in that documentation for casing between *const () to fn pointers.
9697
let cb: TracingCb = unsafe { std::mem::transmute(cb) };
9798

@@ -102,10 +103,10 @@ extern "C" fn tracing_cb_c(level: raw::git_trace_level_t, msg: *const c_char) {
102103
}
103104

104105
// Convert the message from a *const c_char to a &[u8] and pass it to the callback.
105-
//
106-
// SAFETY: We've just checked that the pointer is not null. The other safety requirements are left to
106+
//
107+
// SAFETY: We've just checked that the pointer is not null. The other safety requirements are left to
107108
// libgit2 to enforce -- namely that it gives us a valid, nul-terminated, C string, that that string exists
108-
// entirely in one allocation, that the string will not be mutated once passed to us, and that the nul-terminator is
109+
// entirely in one allocation, that the string will not be mutated once passed to us, and that the nul-terminator is
109110
// within isize::MAX bytes from the given pointers data address.
110111
let msg: &CStr = unsafe { CStr::from_ptr(msg) };
111112

@@ -116,7 +117,7 @@ extern "C" fn tracing_cb_c(level: raw::git_trace_level_t, msg: *const c_char) {
116117
panic::wrap(|| {
117118
// Convert the raw trace level into a type we can pass to the rust callback fn.
118119
//
119-
// SAFETY: Currently the implementation of this function (above) may panic, but is only marked as unsafe to match
120+
// SAFETY: Currently the implementation of this function (above) may panic, but is only marked as unsafe to match
120121
// the trait definition, thus we can consider this call safe.
121122
let level: TraceLevel = unsafe { Binding::from_raw(level) };
122123

@@ -134,6 +135,7 @@ mod tests {
134135
fn smoke() {
135136
super::trace_set(TraceLevel::Trace, |level, msg| {
136137
dbg!(level, msg);
137-
}).expect("libgit2 can set global trace callback");
138+
})
139+
.expect("libgit2 can set global trace callback");
138140
}
139141
}

0 commit comments

Comments
 (0)