From 402727c7f9e0e522908c1441808d7cbc0f029783 Mon Sep 17 00:00:00 2001 From: Ar37-rs Date: Sat, 1 Oct 2022 11:24:48 +0700 Subject: [PATCH] Clean up. --- CHANGELOG.md | 3 ++- Cargo.toml | 3 ++- examples/compact.rs | 12 ++++++------ src/compact.rs | 7 ++++++- src/lib.rs | 12 ++++++------ 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bce886..8d31f85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog -## [5.0.1] - 2022-10-1 +## [5.1.0] - 2022-10-1 +- Clean up code. - On Error: Support handling unexpected panic at runtime. - Added CompactFlower, a Flower with composable error message (can be enabled using `features = ["compact"]` ) diff --git a/Cargo.toml b/Cargo.toml index c9ca8fd..e306232 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flowync" -version = "5.0.1" +version = "5.1.0" authors = ["Ar37-rs "] edition = "2021" description = "A simple utility for multithreading a/synchronization" @@ -12,6 +12,7 @@ repository = "https://github.com/Ar37-rs/flowync" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] +default = ["compact"] compact = [] [[example]] diff --git a/examples/compact.rs b/examples/compact.rs index 194f023..d896837 100644 --- a/examples/compact.rs +++ b/examples/compact.rs @@ -10,7 +10,7 @@ enum ErrMessage { Other, } -type TestFlower = CompactFlower; +type TestCompactFlower = CompactFlower; fn fetch_things(id: usize) -> Result { let result = Ok::(format!( @@ -22,9 +22,9 @@ fn fetch_things(id: usize) -> Result { } fn main() { - let flower: TestFlower = CompactFlower::new(1); + let compact_flower: TestCompactFlower = CompactFlower::new(1); std::thread::spawn({ - let handle = flower.handle(); + let handle = compact_flower.handle(); // Activate handle.activate(); move || { @@ -47,14 +47,14 @@ fn main() { let mut exit = false; loop { - // Check if the flower is_active() + // Check if the compact flower is_active() // and will deactivate itself if the result value successfully received. - if flower.is_active() { + if compact_flower.is_active() { // another logic goes here... // e.g: // notify_loading_fn(); - flower + compact_flower .poll(|channel| { if let Some(value) = channel { println!("{}", value); diff --git a/src/compact.rs b/src/compact.rs index 5a7f40a..5e91da3 100644 --- a/src/compact.rs +++ b/src/compact.rs @@ -14,6 +14,7 @@ enum CompactTypeOpt where S: Send, R: Send, + E: Send, { Channel(S), Success(R), @@ -25,6 +26,7 @@ impl Default for CompactTypeOpt where S: Send, R: Send, + E: Send, { fn default() -> Self { Self::None @@ -35,7 +37,7 @@ impl Debug for CompactTypeOpt where S: Send + Debug, R: Send + Debug, - E: std::fmt::Debug, + E: Send + Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { @@ -51,6 +53,7 @@ impl CompactTypeOpt where S: Send, R: Send, + E: Send, { fn take(&mut self) -> Self { mem::take(self) @@ -61,6 +64,7 @@ struct InnerState where S: Send, R: Send, + E: Send, { activated: AtomicBool, result_ready: AtomicBool, @@ -92,6 +96,7 @@ impl Drop for InnerState where S: Send, R: Send, + E: Send, { fn drop(&mut self) {} } diff --git a/src/lib.rs b/src/lib.rs index 7ca855a..94f47ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,8 +81,8 @@ where impl Debug for InnerState where - S: Debug + Send, - R: Debug + Send, + S: Send + Debug, + R: Send + Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("InnerState") @@ -311,8 +311,8 @@ where impl Debug for Handle where - S: Debug + Send, - R: Debug + Send, + S: Send + Debug, + R: Send + Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("Handle") @@ -597,8 +597,8 @@ where impl Debug for Flower where - S: Debug + Send, - R: Debug + Send, + S: Send + Debug, + R: Send + Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("Flower")