diff --git a/CHANGELOG.md b/CHANGELOG.md index b28146b..0d62175 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ # Changelog -## [4.6.2] - 2022-9-27 +## [4.6.3] - 2022-9-28 - Make Flower uncloneable to avoid any kind of data races, added FlowerState as alternative. - Internal only: Replace `Option` with `TypeOpt` managing value of the sync (mtx) state. +- Revert: don't use trait bound `Clone` on type `` +- Added functionality to set verboser error message using `fn error_verbose`. ## [4.6.0] - 2022-9-26 - Added 'set_result` and `try_result` fn for more simpler error handling. diff --git a/Cargo.toml b/Cargo.toml index 6f5074c..e089017 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flowync" -version = "4.6.2" +version = "4.6.3" authors = ["Ar37-rs "] edition = "2021" description = "A simple utility for multithreading a/synchronization" diff --git a/examples/tokio_full.rs b/examples/tokio_full.rs index 209f5d4..966b838 100644 --- a/examples/tokio_full.rs +++ b/examples/tokio_full.rs @@ -29,7 +29,7 @@ async fn main() { } Err(e) => { // Return error immediately if something not right, for example: - return this.error(e); + return this.error_verbose(e.into()); } } diff --git a/examples/vectored_tasks.rs b/examples/vectored_tasks.rs index 00d31a6..4184fd4 100644 --- a/examples/vectored_tasks.rs +++ b/examples/vectored_tasks.rs @@ -37,7 +37,7 @@ fn main() { } Err(e) => { // Return error immediately if something not right, for example: - return this.error(e); + return this.error_verbose(e.into()); } } diff --git a/src/lib.rs b/src/lib.rs index 82d6f1c..9ae96f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -249,8 +249,18 @@ where .await } - /// Set result value + /// Set `Result` value with verboser error message. + /// + /// (for more easier to keep in track with the real cause of the error) pub fn set_result(&self, r: Result>) { + match r { + Ok(val) => self.success(val), + Err(e) => self.error_verbose(e), + } + } + + /// Set `Result` value with no verbose (simpler error message) + pub fn set_result_no_verbose(&self, r: Result>) { match r { Ok(val) => self.success(val), Err(e) => self.error(e), @@ -268,6 +278,13 @@ where *self.state.mtx.lock().unwrap() = TypeOpt::Error(e.to_string()); self.state.result_ready.store(true, Ordering::Relaxed); } + + /// Set the Err value of the result with more verboser error message. + pub fn error_verbose(&self, e: Box) { + let err_kind = format!("{:?}", e); + *self.state.mtx.lock().unwrap() = TypeOpt::Error(err_kind); + self.state.result_ready.store(true, Ordering::Relaxed); + } } impl Clone for Handle