Showing the changes to git-object/src/object (1 of 2 files). Show all
Unified · Split
| @@ -24,6 +24,34 @@ mod write { · 23 unmodified lines | |||
| 24 | 24 | ||
| 25 | /// Convenient extraction of typed object. | 25 | /// Convenient extraction of typed object. |
| 26 | impl Object { | 26 | 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 | } | ||
| 27 | /// Returns a [`Blob`][Blob] if it is one. | 55 | /// Returns a [`Blob`][Blob] if it is one. |
| 28 | pub fn as_blob(&self) -> Option<&Blob> { | 56 | pub fn as_blob(&self) -> Option<&Blob> { |
| 29 | match self { | 57 | match self { |