Skip to content

Commit 78bacf9

Browse files
committed
[object #190] More conversion methods for Object
1 parent 26a6637 commit 78bacf9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

git-object/src/object/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,34 @@ mod write {
2424

2525
/// Convenient extraction of typed object.
2626
impl Object {
27+
/// Turns this instance into a [`Blob`][Blob] if it is one.
28+
pub fn into_blob(self) -> Option<Blob> {
29+
match self {
30+
Object::Blob(v) => Some(v),
31+
_ => None,
32+
}
33+
}
34+
/// Turns this instance into a [`Commit`][Commit] if it is one.
35+
pub fn into_commit(self) -> Option<Commit> {
36+
match self {
37+
Object::Commit(v) => Some(v),
38+
_ => None,
39+
}
40+
}
41+
/// Turns this instance into a [`Tree`][Tree] if it is one.
42+
pub fn into_tree(self) -> Option<Tree> {
43+
match self {
44+
Object::Tree(v) => Some(v),
45+
_ => None,
46+
}
47+
}
48+
/// Turns this instance into a [`Tag`][Tag] if it is one.
49+
pub fn into_tag(self) -> Option<Tag> {
50+
match self {
51+
Object::Tag(v) => Some(v),
52+
_ => None,
53+
}
54+
}
2755
/// Returns a [`Blob`][Blob] if it is one.
2856
pub fn as_blob(&self) -> Option<&Blob> {
2957
match self {

git-ref/src/store/file/log/iter.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ pub fn forward(lines: &[u8]) -> impl Iterator<Item = Result<log::LineRef<'_>, de
6161
}
6262

6363
/// An iterator yielding parsed lines in a file in reverse.
64-
#[allow(dead_code)]
6564
pub struct Reverse<'a, F> {
6665
buf: &'a mut [u8],
6766
count: usize,

0 commit comments

Comments
 (0)