From bfef058f199d195bb2c16d791c3f1bfeccb5614e Mon Sep 17 00:00:00 2001 From: Vika Date: Wed, 4 Aug 2021 13:28:24 +0300 Subject: Fixed a VERY WRONG way to handle stream errors for future reference: stream operations returning Result satisfy conditions for the futures::stream::TryStreamExt trait, allowing you to use `TryStreamExt::try_collect::()` and receive a Result. --- src/database/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/database/mod.rs') diff --git a/src/database/mod.rs b/src/database/mod.rs index 27c0025..7b144f8 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -90,12 +90,20 @@ impl serde::Serialize for StorageError { impl StorageError { /// Create a new StorageError of an ErrorKind with a message. fn new(kind: ErrorKind, msg: &str) -> Self { - StorageError { + Self { msg: msg.to_string(), source: None, kind, } } + /// Create a StorageError using another arbitrary Error as a source. + fn with_source(kind: ErrorKind, msg: &str, source: Box) -> Self { + Self { + msg: msg.to_string(), + source: Some(source), + kind + } + } /// Get the kind of an error. pub fn kind(&self) -> ErrorKind { self.kind -- cgit 1.4.1