Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* dev:
  changlog + version bump
  fix clippy warnings
  Remove the pointer and closure methods after all
  Try to fix docs.rs readme
  • Loading branch information
najamelan committed Sep 23, 2019
2 parents fc30cbf + f706303 commit d26d98d
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 90 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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, ...

Expand Down
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,23 @@ pin-project = "^0.4.0-beta"
features = ["async-await", "nightly"]
version = "^0.3.0-alpha"

[dev-dependencies]
assert_matches = "^1"

[features]
external_doc = []

[package]
authors = ["Naja Melan <[email protected]>"]
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
31 changes: 14 additions & 17 deletions Cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ package:
# - merge dev branch into master
# - create git tag
#
version : 0.3.0
name : pharos
authors : [ Naja Melan <[email protected]> ]
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 <[email protected]> ]
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:
Expand All @@ -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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions examples/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ impl<Event> Sender<Event> where Event: Clone + 'static + Send
None => true ,
};


#[ allow( clippy::match_bool ) ]
//
match interested
{
true => tx.send( evt.clone() ).await.is_ok(),
Expand Down
46 changes: 5 additions & 41 deletions src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ use crate :: { import::* };
/// //
/// let predicate = move |_: &bool| { a; true };
///
/// let filter = Filter::<bool>::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::<bool>::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::<bool>::pointer( predicate_function );
/// let filter = Filter::Pointer( predicate_function );
/// ```
//
pub enum Filter<Event>
Expand All @@ -55,24 +55,6 @@ pub enum Filter<Event>

impl<Event> Filter<Event> 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<F>( 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
Expand Down Expand Up @@ -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<bool>::Pointer(_)", &format!( "{:?}", f ) );
assert_eq!( "pharos::Filter<bool>::Closure(_)", &format!( "{:?}", g ) );
Expand Down
8 changes: 0 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,4 @@ mod import
} ,
},
};


#[ cfg( test ) ]
//
pub(crate) use
{
assert_matches :: { assert_matches } ,
};
}
6 changes: 3 additions & 3 deletions src/observable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// //
Expand Down Expand Up @@ -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.
/// //
Expand Down Expand Up @@ -206,7 +206,7 @@ impl<Event> ObserveConfig<Event> 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
}
}
Expand Down
16 changes: 5 additions & 11 deletions src/pharos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ impl<Event> Pharos<Event> 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 )
}
}

Expand Down Expand Up @@ -135,15 +134,10 @@ impl<Event> Pharos<Event> 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 );
}
}
}
Expand Down

0 comments on commit d26d98d

Please sign in to comment.