Skip to content

Commit e158e43

Browse files
committed
Make Binding public
1 parent 3df7e81 commit e158e43

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub use crate::tracing::{trace_set, TraceLevel};
139139
pub use crate::transaction::Transaction;
140140
pub use crate::tree::{Tree, TreeEntry, TreeIter, TreeWalkMode, TreeWalkResult};
141141
pub use crate::treebuilder::TreeBuilder;
142-
pub use crate::util::IntoCString;
142+
pub use crate::util::{Binding, IntoCString};
143143
pub use crate::version::Version;
144144
pub use crate::worktree::{Worktree, WorktreeAddOptions, WorktreeLockStatus, WorktreePruneOptions};
145145

src/util.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,27 @@ impl<T> IsNull for *mut T {
2121
}
2222
}
2323

24-
#[doc(hidden)]
24+
/// Provides access to the raw libgit2 pointer to be able to interact with libgit2-sys.
25+
///
26+
/// If you are going to depend on this trait on your code, do consider contributing to the git2
27+
/// project to add the missing capabilities to git2.
2528
pub trait Binding: Sized {
29+
/// The raw type that allows you to interact with libgit2-sys.
2630
type Raw;
2731

32+
/// Build a git2 struct from its [Binding::Raw] value.
2833
unsafe fn from_raw(raw: Self::Raw) -> Self;
34+
35+
/// Access the [Binding::Raw] value for a struct.
36+
///
37+
/// The returned value is only safe to use while its associated git2 struct is in scope.
38+
/// Once the associated git2 struct is destroyed, the raw value can point to an invalid memory address.
2939
fn raw(&self) -> Self::Raw;
3040

41+
/// A null-handling version of [Binding::from_raw].
42+
///
43+
/// If the input parameter is null, then the funtion returns None. Otherwise, it
44+
/// calls [Binding::from_raw].
3145
unsafe fn from_raw_opt<T>(raw: T) -> Option<Self>
3246
where
3347
T: Copy + IsNull,

0 commit comments

Comments
 (0)