From 0585e43fa82a359e768815394b493801773feb0c Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 17 Aug 2020 14:52:11 +0200 Subject: add Log::errors convenience method --- CHANGELOG.md | 3 +++ examples/loginfo.rs | 4 ++++ src/lib.rs | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7c6b4b..3450b48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. ## Unreleased +### Added +- `Log::errors` as a convenience function. + ### Fixed - Fixed the conversion from `CBTS_ERROR` to `EventKind::Error` not having the correct text. diff --git a/examples/loginfo.rs b/examples/loginfo.rs index 927ff52..978fede 100644 --- a/examples/loginfo.rs +++ b/examples/loginfo.rs @@ -36,4 +36,8 @@ fn main() { } println!("Number of recorded events: {}", log.events().len()); + + for error in log.errors() { + println!("Error in log: {}", error); + } } diff --git a/src/lib.rs b/src/lib.rs index b3c587d..cd483da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -897,4 +897,20 @@ impl Log { } }) } + + /// Returns all error strings that were captured. + /// + /// If no errors were encountered, an empty vec is returned. + /// + /// Note that those are errors reported verbatim by arcdps, nothing that evtclib + /// produces/interprets. + pub fn errors(&self) -> Vec<&str> { + self.events().iter().filter_map(|e| { + if let EventKind::Error { ref text } = e.kind() { + Some(text as &str) + } else { + None + } + }).collect() + } } -- cgit v1.2.3