History

[object #190] More conversion methods for Object

Sebastian Thiel committed 5 years ago

Commit 78bacf91 parent 26a66372 files · +28 −1Browse files

Unified · Split

2 files
  1. git-object/src/object/mod.rs +28 −0
  2. git-ref/src/store/file/log/iter.rs +0 −1
git-object/src/object/mod.rs+28−0
@@ -24,6 +24,34 @@ mod write { · 23 unmodified lines
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+0−1
@@ -61,7 +61,6 @@ pub fn forward(lines: &[u8]) -> impl Iterator<Item = Result<log::LineRef<'_>, de · 60 unmodified lines
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,