Extract search of digest item into Digest::log() function (#874)

* Digest::log fn

* change DigestItem::log impl
This commit is contained in:
Svyatoslav Nikolsky
2018-10-05 15:17:00 +03:00
committed by Gav Wood
parent 187c232629
commit 200a716a1a
4 changed files with 10 additions and 10 deletions
@@ -503,6 +503,13 @@ pub trait Digest: Member + Default {
fn logs(&self) -> &[Self::Item];
/// Push new digest item.
fn push(&mut self, item: Self::Item);
/// Get reference to the first digest item that matches the passed predicate.
fn log<T, F: Fn(&Self::Item) -> Option<&T>>(&self, predicate: F) -> Option<&T> {
self.logs().iter()
.filter_map(predicate)
.next()
}
}
/// Single digest item. Could be any type that implements `Member` and provides methods