1
+ //! Contains a borrowed Object bound to a buffer holding its decompressed data.
1
2
use git_object:: borrowed;
2
3
3
4
/// A borrowed object using a borrowed slice as backing buffer.
@@ -8,6 +9,11 @@ pub struct Object<'a> {
8
9
}
9
10
10
11
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()`].
11
17
pub fn decode ( & self ) -> Result < borrowed:: Object < ' _ > , borrowed:: Error > {
12
18
Ok ( match self . kind {
13
19
git_object:: Kind :: Tree => borrowed:: Object :: Tree ( borrowed:: Tree :: from_bytes ( self . data ) ?) ,
@@ -18,6 +24,7 @@ impl<'a> Object<'a> {
18
24
}
19
25
}
20
26
27
+ /// Types supporting object hash verification
21
28
pub mod verify {
22
29
use crate :: { hash, loose} ;
23
30
use git_object:: { borrowed, owned} ;
@@ -30,6 +37,9 @@ pub mod verify {
30
37
}
31
38
32
39
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`.
33
43
pub fn verify_checksum ( & self , desired : borrowed:: Id < ' _ > ) -> Result < ( ) , Error > {
34
44
let mut sink = hash:: Write :: new ( io:: sink ( ) , desired. kind ( ) ) ;
35
45
0 commit comments