1
- mod error;
2
- pub use error:: Error ;
1
+ use bstr:: BStr ;
3
2
4
- use crate :: BStr ;
5
3
use crate :: {
6
4
borrowed,
7
5
borrowed:: { parse, Blob , Commit , Tag , Tree } ,
8
- Time ,
6
+ Kind , Time ,
9
7
} ;
10
8
9
+ mod error;
10
+ pub use error:: Error ;
11
+
11
12
#[ derive( PartialEq , Eq , Debug , Hash , Ord , PartialOrd , Clone ) ]
12
13
#[ cfg_attr( feature = "serde1" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
13
14
pub struct Signature < ' a > {
@@ -33,6 +34,18 @@ pub enum Object<'a> {
33
34
Blob ( Blob < ' a > ) ,
34
35
}
35
36
37
+ impl < ' a > Object < ' a > {
38
+ pub fn from_bytes ( kind : Kind , bytes : & ' a [ u8 ] ) -> Result < Object < ' a > , Error > {
39
+ Ok ( match kind {
40
+ Kind :: Tag => Object :: Tag ( Tag :: from_bytes ( bytes) ?) ,
41
+ Kind :: Tree => Object :: Tree ( Tree :: from_bytes ( bytes) ?) ,
42
+ Kind :: Commit => Object :: Commit ( Commit :: from_bytes ( bytes) ?) ,
43
+ Kind :: Blob => Object :: Blob ( Blob { data : bytes } ) ,
44
+ } )
45
+ }
46
+ }
47
+
48
+ /// Convenient access to contained objects
36
49
impl < ' a > Object < ' a > {
37
50
pub fn as_blob ( & self ) -> Option < & borrowed:: Blob > {
38
51
match self {
@@ -58,12 +71,12 @@ impl<'a> Object<'a> {
58
71
_ => None ,
59
72
}
60
73
}
61
- pub fn kind ( & self ) -> crate :: Kind {
74
+ pub fn kind ( & self ) -> Kind {
62
75
match self {
63
- Object :: Tag ( _) => crate :: Kind :: Tag ,
64
- Object :: Commit ( _) => crate :: Kind :: Commit ,
65
- Object :: Tree ( _) => crate :: Kind :: Tree ,
66
- Object :: Blob ( _) => crate :: Kind :: Blob ,
76
+ Object :: Tag ( _) => Kind :: Tag ,
77
+ Object :: Commit ( _) => Kind :: Commit ,
78
+ Object :: Tree ( _) => Kind :: Tree ,
79
+ Object :: Blob ( _) => Kind :: Blob ,
67
80
}
68
81
}
69
82
}
0 commit comments