Skip to content

Commit 7626f7f

Browse files
committed
Document borrowed odb objects
1 parent 60666e8 commit 7626f7f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

git-object/src/borrowed/object.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ impl<'a> Object<'a> {
4343
Kind::Tag => Object::Tag(Tag::from_bytes(bytes)?),
4444
})
4545
}
46+
47+
pub fn into_owned(self) -> crate::owned::Object {
48+
self.into()
49+
}
4650
}
4751

4852
/// Convenient access to contained objects

git-odb/src/borrowed.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Contains a borrowed Object bound to a buffer holding its decompressed data.
12
use git_object::borrowed;
23

34
/// A borrowed object using a borrowed slice as backing buffer.
@@ -8,6 +9,11 @@ pub struct Object<'a> {
89
}
910

1011
impl<'a> Object<'a> {
12+
/// Decodes the data in the backing slice into a [`borrowed::Object`], allowing to access all of its data
13+
/// conveniently. The cost of parsing an object is negligible.
14+
///
15+
/// **Note** that [owned, decoded objects][git_object::owned::Object] can be created from a [`borrowed::Object`]
16+
/// using [`borrowed::Object::into_owned()`].
1117
pub fn decode(&self) -> Result<borrowed::Object<'_>, borrowed::Error> {
1218
Ok(match self.kind {
1319
git_object::Kind::Tree => borrowed::Object::Tree(borrowed::Tree::from_bytes(self.data)?),
@@ -18,6 +24,7 @@ impl<'a> Object<'a> {
1824
}
1925
}
2026

27+
/// Types supporting object hash verification
2128
pub mod verify {
2229
use crate::{hash, loose};
2330
use git_object::{borrowed, owned};
@@ -30,6 +37,9 @@ pub mod verify {
3037
}
3138

3239
impl crate::borrowed::Object<'_> {
40+
/// Compute the checksum of `self` and compare it with the `desired` hash.
41+
/// If the hashes do not match, an [`Error`] is returned, containing the actual
42+
/// hash of `self`.
3343
pub fn verify_checksum(&self, desired: borrowed::Id<'_>) -> Result<(), Error> {
3444
let mut sink = hash::Write::new(io::sink(), desired.kind());
3545

0 commit comments

Comments
 (0)