diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e8c401..c784c90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Pharos Changelog +## 0.5.1 - 2020-02-18 + +- Add `ObservableLocal` for observable types that are `!Send`. + ## 0.5.0 - 2020-02-17 - **BREAKING CHANGE**: `Observable::observe` is now an async function. This was needed to make it possible to send diff --git a/Cargo.toml b/Cargo.toml index 7c06dc4..a5f86ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ license = "Unlicense" name = "pharos" readme = "README.md" repository = "https://github.com/najamelan/pharos" -version = "0.5.0" +version = "0.5.1" [package.metadata] [package.metadata.docs] diff --git a/Cargo.yml b/Cargo.yml index 751857b..92c6a32 100644 --- a/Cargo.yml +++ b/Cargo.yml @@ -24,7 +24,7 @@ package: # - `git tag x.x.x` with version number. # - `git push && git push --tags` # - version : 0.5.0 + version : 0.5.1 name : pharos authors : [ Naja Melan ] edition : '2018' @@ -59,7 +59,7 @@ dev-dependencies: futures : ^0.3 assert_matches : ^1 - async-std : { version: ^1, features: [attributes] } + async-std : { version: ^1 , features: [attributes] } async_executors : { version: ^0.4, features: [ async_std ] } wasm-bindgen-test : ^0.3 diff --git a/README.md b/README.md index 75dcf6d..0b46c5b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # pharos [![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) -[![Build Status](https://api.travis-ci.org/najamelan/pharos.svg?branch=master)](https://travis-ci.org/najamelan/pharos) +[![Build Status](https://github.com/najamelan/pharos/workflows/ci/badge.svg?branch=master)](https://github.com/najamelan/pharos/actions) [![Docs](https://docs.rs/pharos/badge.svg)](https://docs.rs/pharos) [![Crates.io](https://img.shields.io/crates/v/pharos)](https://crates.io/crates/pharos) [![Crates.io downloads](https://img.shields.io/crates/d/pharos)](https://crates.io/crates/pharos) diff --git a/src/lib.rs b/src/lib.rs index 1224172..e377a38 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,12 +34,12 @@ mod shared_pharos ; pub use { - self::pharos :: { Pharos } , - filter :: { Filter } , - observable :: { Observable, ObserveConfig, Channel } , - events :: { Events } , - error :: { PharErr, ErrorKind } , - shared_pharos:: { SharedPharos } , + self::pharos :: { Pharos } , + filter :: { Filter } , + observable :: { Observable, ObservableLocal, ObserveConfig, Channel } , + events :: { Events } , + error :: { PharErr, ErrorKind } , + shared_pharos:: { SharedPharos } , }; @@ -77,3 +77,7 @@ use import::*; /// A pinned boxed future returned by the Observable::observe method. // pub type Observe<'a, Event, Error> = Pin, Error> > + 'a + Send >>; + +/// A pinned boxed future returned by the ObservableLocal::observe_local method. +// +pub type ObserveLocal<'a, Event, Error> = Pin, Error> > + 'a >>; diff --git a/src/observable.rs b/src/observable.rs index f1e2e7b..c36d9c6 100644 --- a/src/observable.rs +++ b/src/observable.rs @@ -1,4 +1,4 @@ -use crate :: { Filter, Observe }; +use crate :: { Filter, Observe, ObserveLocal }; /// Indicate that a type is observable. You can call [`observe`](Observable::observe) to get a /// stream of events. @@ -95,6 +95,32 @@ pub trait Observable } +/// Like Observable, but the future returned is not `Send`, thus the observable type does not need to be `Send`. +// +pub trait ObservableLocal + + where Event: Clone + 'static + Send , +{ + /// The error type that is returned if observing is not possible. + /// + /// [Pharos](crate::Pharos) implements + /// [Sink](https://docs.rs/futures-preview/0.3.0-alpha.19/futures/sink/trait.Sink.html) + /// which has a close method, so observing will no longer be possible after close is called. + /// + /// Other than that, you might want to have moments in your objects lifetime when you don't want to take + /// any more observers. Returning a result from [observe](Observable::observe) enables that. + /// + /// You can of course map the error of pharos to your own error type. + // + type Error: std::error::Error; + + /// Add an observer to the observable. Options allow chosing the channel type and + /// to filter events with a predicate. + // + fn observe_local( &mut self, options: ObserveConfig ) -> ObserveLocal<'_, Event, Self::Error >; +} + + /// Choose the type of channel that will be used for your event stream. Used in [ObserveConfig]. //