Skip to content

Commit b238d16

Browse files
authored
Merge pull request #940 from edrevo/public-binding
Make Binding public
2 parents 9dfe8db + 1c94d61 commit b238d16

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub use crate::tracing::{trace_set, TraceLevel};
142142
pub use crate::transaction::Transaction;
143143
pub use crate::tree::{Tree, TreeEntry, TreeIter, TreeWalkMode, TreeWalkResult};
144144
pub use crate::treebuilder::TreeBuilder;
145-
pub use crate::util::IntoCString;
145+
pub use crate::util::{Binding, IntoCString};
146146
pub use crate::version::Version;
147147
pub use crate::worktree::{Worktree, WorktreeAddOptions, WorktreeLockStatus, WorktreePruneOptions};
148148

src/util.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,27 @@ impl<T> IsNull for *mut T {
2020
}
2121
}
2222

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

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

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

0 commit comments

Comments
 (0)