History

feat: `CommitRefIter::(author|committer)()`, better usability (#364)

The methods returning an iterator are now consuming, which allows them to be nested by callers.

Sebastian Thiel committed 4 years ago

Commit c51a9251 parent 91065cd2 files · +41 −20Browse files

Showing the changes to git-object/src/commit (1 of 2 files). Show all

Unified · Split

git-object/src/commit/ref_iter.rs+18−0
@@ -83,6 +83,24 @@ impl<'a> CommitRefIter<'a> { · 82 unmodified lines
83 _ => None,83 _ => None,
84 })84 })
85 }85 }
86
87 /// Returns the author signature if there is no decoding error.
88 /// Errors are coerced into options, hiding whether there was an error or not. The caller knows if there was an error or not.
89 pub fn author(&mut self) -> Option<git_actor::SignatureRef<'_>> {
90 self.find_map(|t| match t {
91 Ok(Token::Author { signature }) => Some(signature),
92 _ => None,
93 })
94 }
95
96 /// Returns the message if there is no decoding error.
97 /// Errors are coerced into options, hiding whether there was an error or not. The caller knows if there was an error or not.
98 pub fn message(&mut self) -> Option<&'a BStr> {
99 self.find_map(|t| match t {
100 Ok(Token::Message(msg)) => Some(msg),
101 _ => None,
102 })
103 }
86}104}
87 105
88impl<'a> CommitRefIter<'a> {106impl<'a> CommitRefIter<'a> {