Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* dev:
  Fix badge, again.
  Add `ObservableLocal` for observable types that are `!Send`.
  Fix build status badge.
  • Loading branch information
najamelan committed Feb 18, 2021
2 parents be16c87 + b6f6914 commit ad32f2a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
4 changes: 4 additions & 0 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions Cargo.yml
Expand Up @@ -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 <najamelan@autistici.org> ]
edition : '2018'
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion 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)
Expand Down
16 changes: 10 additions & 6 deletions src/lib.rs
Expand Up @@ -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 } ,
};


Expand Down Expand Up @@ -77,3 +77,7 @@ use import::*;
/// A pinned boxed future returned by the Observable::observe method.
//
pub type Observe<'a, Event, Error> = Pin<Box< dyn Future< Output = Result<Events<Event>, Error> > + 'a + Send >>;

/// A pinned boxed future returned by the ObservableLocal::observe_local method.
//
pub type ObserveLocal<'a, Event, Error> = Pin<Box< dyn Future< Output = Result<Events<Event>, Error> > + 'a >>;
28 changes: 27 additions & 1 deletion 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.
Expand Down Expand Up @@ -95,6 +95,32 @@ pub trait Observable<Event>
}


/// Like Observable, but the future returned is not `Send`, thus the observable type does not need to be `Send`.
//
pub trait ObservableLocal<Event>

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<Event> ) -> ObserveLocal<'_, Event, Self::Error >;
}



/// Choose the type of channel that will be used for your event stream. Used in [ObserveConfig].
//
Expand Down

0 comments on commit ad32f2a

Please sign in to comment.