Skip to content

Commit 79c0267

Browse files
committed
refactor: Use ptr::NonNull and marker::PhantomData
This is mostly to bring it inline with the other modules' code style.
1 parent 314813a commit 79c0267

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/odb_backend.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use crate::{raw, Error, ErrorClass, ErrorCode, ObjectType, Oid};
66
use bitflags::bitflags;
77
use std::marker::PhantomData;
88
use std::mem::ManuallyDrop;
9-
use std::ptr::NonNull;
10-
use std::{ptr, slice};
9+
use std::{marker, ptr, slice};
1110

1211
/// A custom implementation of an [`Odb`](crate::Odb) backend.
1312
///
@@ -347,7 +346,7 @@ bitflags! {
347346
/// [`git_odb_backend_data_free`]: raw::git_odb_backend_data_free
348347
pub struct OdbBackendAllocation {
349348
backend_ptr: *mut raw::git_odb_backend,
350-
raw: NonNull<libc::c_void>,
349+
raw: ptr::NonNull<libc::c_void>,
351350
size: usize,
352351
}
353352
impl OdbBackendAllocation {
@@ -374,7 +373,7 @@ impl OdbBackendContext {
374373
pub const fn alloc_0(&self) -> OdbBackendAllocation {
375374
OdbBackendAllocation {
376375
backend_ptr: self.backend_ptr,
377-
raw: NonNull::dangling(),
376+
raw: ptr::NonNull::dangling(),
378377
size: 0,
379378
}
380379
}
@@ -387,7 +386,7 @@ impl OdbBackendContext {
387386
pub fn alloc(&self, size: usize) -> Option<OdbBackendAllocation> {
388387
let data =
389388
unsafe { raw::git_odb_backend_data_alloc(self.backend_ptr, size as libc::size_t) };
390-
let data = NonNull::new(data)?;
389+
let data = ptr::NonNull::new(data)?;
391390
Some(OdbBackendAllocation {
392391
backend_ptr: self.backend_ptr,
393392
raw: data,
@@ -416,8 +415,8 @@ impl OdbBackendContext {
416415
/// A handle to an [`OdbBackend`] that has been added to an [`Odb`](crate::Odb).
417416
pub struct CustomOdbBackend<'a, B: OdbBackend> {
418417
// NOTE: Any pointer in this field must be both non-null and properly aligned.
419-
raw: NonNull<Backend<B>>,
420-
phantom: PhantomData<fn() -> &'a ()>,
418+
raw: ptr::NonNull<Backend<B>>,
419+
phantom: marker::PhantomData<fn() -> &'a ()>,
421420
}
422421

423422
impl<'a, B: OdbBackend> CustomOdbBackend<'a, B> {
@@ -450,10 +449,10 @@ impl<'a, B: OdbBackend> CustomOdbBackend<'a, B> {
450449
pub(crate) fn new(backend: Box<Backend<B>>) -> Self {
451450
// SAFETY: Box::into_raw guarantees that the pointer is properly aligned and non-null
452451
let backend = Box::into_raw(backend);
453-
let backend = unsafe { NonNull::new_unchecked(backend) };
452+
let backend = unsafe { ptr::NonNull::new_unchecked(backend) };
454453
Self {
455454
raw: backend,
456-
phantom: PhantomData,
455+
phantom: marker::PhantomData,
457456
}
458457
}
459458

@@ -598,7 +597,7 @@ impl<B: OdbBackend> Backend<B> {
598597
.inner
599598
.read_header(&context, oid, size, &mut object_type)
600599
{
601-
unsafe { return e.raw_set_git_error() }
600+
return unsafe { e.raw_set_git_error() };
602601
};
603602
*otype = object_type.raw();
604603

0 commit comments

Comments
 (0)