diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d1ab36..bc359f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Pharos Changelog -## 0.3.0 - 2019-09-23 +## 0.3.1 - 2019-09-23 + +**BREAKING CHANGE**: Last minute change of heart. I removed two API methods whose only "merit" was +to hide a Box::new from the user. + +## 0.3.0 - 2019-09-23 - yanked **BREAKING CHANGE**: This is an almost complete rewrite with a much improved API, documentation, ... diff --git a/Cargo.toml b/Cargo.toml index 81b8183..71b6977 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,6 @@ pin-project = "^0.4.0-beta" features = ["async-await", "nightly"] version = "^0.3.0-alpha" -[dev-dependencies] -assert_matches = "^1" - [features] external_doc = [] @@ -23,14 +20,16 @@ external_doc = [] authors = ["Naja Melan "] categories = ["asynchronous"] description = "Observer pattern which generates a futures 0.3 stream of events" +documentation = "https://docs.rs/pharos" edition = "2018" keywords = ["observer", "futures", "stream", "broadcast", "publish_subscribe"] license = "Unlicense" name = "pharos" readme = "README.md" repository = "https://github.com/najamelan/pharos" -version = "0.3.0" +version = "0.3.1" [package.metadata] -[package.metadata."docs.rs"] +[package.metadata.docs] +[package.metadata.docs.rs] all-features = true diff --git a/Cargo.yml b/Cargo.yml index 69d53fa..3f3289d 100644 --- a/Cargo.yml +++ b/Cargo.yml @@ -10,21 +10,22 @@ package: # - merge dev branch into master # - create git tag # - version : 0.3.0 - name : pharos - authors : [ Naja Melan ] - edition : '2018' - readme : README.md - license : Unlicense - - repository : https://github.com/najamelan/pharos - description : Observer pattern which generates a futures 0.3 stream of events - categories : [ asynchronous ] - keywords : [ observer, futures, stream, broadcast, publish_subscribe ] + version : 0.3.1 + name : pharos + authors : [ Naja Melan ] + edition : '2018' + readme : README.md + license : Unlicense + repository : https://github.com/najamelan/pharos + documentation : https://docs.rs/pharos + description : Observer pattern which generates a futures 0.3 stream of events + categories : [ asynchronous ] + keywords : [ observer, futures, stream, broadcast, publish_subscribe ] metadata: - docs.rs: - all-features: true + docs: + rs: + all-features: true features: @@ -45,7 +46,3 @@ dependencies: futures-preview : { version: ^0.3.0-alpha, features: [async-await, nightly] } pin-project : ^0.4.0-beta - -dev-dependencies: - - assert_matches: ^1 diff --git a/README.md b/README.md index cf29c43..730fa93 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ fn main() // We will only get close events. // - let filter = Filter::pointer( |e| e == &NetworkEvent::Closed ); + let filter = Filter::Pointer( |e| e == &NetworkEvent::Closed ); // By creating the config object through into, other options will be defaults, notably here // this will use unbounded channels. @@ -230,7 +230,7 @@ fn main() // Combine both options. // - let filter = Filter::pointer( |e| e != &NetworkEvent::Closed ); + let filter = Filter::Pointer( |e| e != &NetworkEvent::Closed ); let opts = ObserveConfig::from( filter ).channel( Channel::Bounded(5) ); // Get everything but close events over a bounded channel with queue size 5. diff --git a/examples/filter.rs b/examples/filter.rs index 8fa7e6e..8dda3ce 100644 --- a/examples/filter.rs +++ b/examples/filter.rs @@ -28,7 +28,7 @@ fn main() // We will only get close events. // - let filter = Filter::pointer( |e| e == &NetworkEvent::Closed ); + let filter = Filter::Pointer( |e| e == &NetworkEvent::Closed ); // By creating the config object through into, other options will be defaults, notably here // this will use unbounded channels. @@ -37,7 +37,7 @@ fn main() // Combine both options. // - let filter = Filter::pointer( |e| e != &NetworkEvent::Closed ); + let filter = Filter::Pointer( |e| e != &NetworkEvent::Closed ); let opts = ObserveConfig::from( filter ).channel( Channel::Bounded(5) ); // Get everything but close events over a bounded channel with queue size 5. diff --git a/src/events.rs b/src/events.rs index 7d08f26..cff5d27 100644 --- a/src/events.rs +++ b/src/events.rs @@ -125,6 +125,9 @@ impl Sender where Event: Clone + 'static + Send None => true , }; + + #[ allow( clippy::match_bool ) ] + // match interested { true => tx.send( evt.clone() ).await.is_ok(), diff --git a/src/filter.rs b/src/filter.rs index f7a5835..47aef3c 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -22,20 +22,20 @@ use crate :: { import::* }; /// // /// let predicate = move |_: &bool| { a; true }; /// -/// let filter = Filter::::closure( predicate ); +/// let filter = Filter::Closure( Box::new(predicate) ); /// /// // This one does not capture anything, so it can be stored as a function pointer /// // without boxing. /// // /// let predicate = move |_: &bool| { true }; /// -/// let filter = Filter::::pointer( predicate ); +/// let filter = Filter::Pointer( predicate ); /// /// // You can also use actual functions as filters. /// // /// fn predicate_function( event: &bool ) -> bool { true } /// -/// let filter = Filter::::pointer( predicate_function ); +/// let filter = Filter::Pointer( predicate_function ); /// ``` // pub enum Filter @@ -55,24 +55,6 @@ pub enum Filter impl Filter where Event: Clone + 'static + Send { - /// Construct a filter from a closure that captures something from it's environment. This will - /// be boxed and stored under the [Filter::Closure] variant. To avoid boxing, do not capture - /// any variables from the environment and use [Filter::pointer]. - // - pub fn closure( predicate: F ) -> Self where F: FnMut(&Event) -> bool + Send + 'static - { - Self::Closure( Box::new( predicate ) ) - } - - - /// Construct a filter from a function pointer to a predicate. - // - pub fn pointer( predicate: fn(&Event) -> bool ) -> Self - { - Self::Pointer( predicate ) - } - - /// Invoke the predicate // pub(crate) fn call( &mut self, evt: &Event ) -> bool @@ -107,30 +89,12 @@ mod tests { use super::*; - #[test] - // - fn pointer() - { - let f = Filter::pointer( |b| *b ); - - assert_matches!( f, Filter::Pointer(_) ); - } - - #[test] - // - fn closure() - { - let f = Filter::closure( |b| *b ); - - assert_matches!( f, Filter::Closure(_) ); - } - #[test] // fn debug() { - let f = Filter::pointer( |b| *b ); - let g = Filter::closure( |b| *b ); + let f = Filter::Pointer( |b| *b ); + let g = Filter::Closure( Box::new( |b| *b ) ); assert_eq!( "pharos::Filter::Pointer(_)", &format!( "{:?}", f ) ); assert_eq!( "pharos::Filter::Closure(_)", &format!( "{:?}", g ) ); diff --git a/src/lib.rs b/src/lib.rs index ea16b62..48c8972 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,12 +72,4 @@ mod import } , }, }; - - - #[ cfg( test ) ] - // - pub(crate) use - { - assert_matches :: { assert_matches } , - }; } diff --git a/src/observable.rs b/src/observable.rs index d8fd76c..638cf75 100644 --- a/src/observable.rs +++ b/src/observable.rs @@ -59,7 +59,7 @@ use crate :: { Filter, Events }; /// async fn task() /// { /// let mut foo = Foo { pharos: Pharos::default() }; -/// let mut errors = foo.observe( Filter::pointer( Steps::is_err ).into() ); +/// let mut errors = foo.observe( Filter::Pointer( Steps::is_err ).into() ); /// /// // will only be notified on errors now /// // @@ -134,7 +134,7 @@ impl Default for Channel /// // Use a filter and defaults for other options. /// // Will only receive events if they are bigger than three. /// // -/// pharos.observe( Filter::pointer( |evt| *evt > 3 ).into() ); +/// pharos.observe( Filter::Pointer( |evt| *evt > 3 ).into() ); /// /// // Set both channel and filter. Note you can only set one filter per observable. /// // @@ -206,7 +206,7 @@ impl ObserveConfig where Event: Clone + 'static + Send { debug_assert!( self.filter.is_none(), "You can only set one filter on ObserveConfig" ); - self.filter = Some( Filter::closure(filter) ); + self.filter = Some( Filter::Closure( Box::new(filter) ) ); self } } diff --git a/src/pharos.rs b/src/pharos.rs index 6b1f9a6..e6f0117 100644 --- a/src/pharos.rs +++ b/src/pharos.rs @@ -93,10 +93,9 @@ impl Pharos where Event: 'static + Clone + Send if let Some( mut s ) = opt { - match s.notify( evt ).await + if s.notify( evt ).await { - true => new = Some( s ), - false => {} + new = Some( s ) } } @@ -135,15 +134,10 @@ impl Pharos where Event: 'static + Clone + Send { if let Some(observer) = opt.take() { - match observer.is_closed() + if !observer.is_closed() { - true => {} - - false => - { - count += 1; - *opt = Some( observer ); - } + count += 1; + *opt = Some( observer ); } } }