[][src]Module herald::herald

Herald is a library to help you to track change of your data struct.

Herald require any change of your data struct should represent by a type, and this type should implement LastChange trait.

Herald macro attribute

Herald provide a macro attribute to auto implement Herald, and provide a set of methods to update field. For example

use herald::prelude::*;

#[herald]
struct Point {
    x: f32,
    y: f32
}

let mut p = Point {
    x: 0.,
    y: 0.,
    herald_impl: Default::default(),
};

p.change_stream().subscribe(|v| {
    println!("{:?}", v.borrow().changes)
});

p.set_x(1.);
p.set_y(1.);

// Will print like below
//
// PointChange { x: Some(Change { before: 0.0, after: 1.0 }), y: None }
// PointChange { x: None, y: Some(Change { before: 0.0, after: 1.0 })

what features herald attribute provide?

todo

what herald attr do ?

herald attr will implement a Herald for your struct, and a set of set method provide to update struct, any update across these method will be tracked.

Assume we have below code

#[herald]
struct Point {
    x: f32,
    y: f32
}

First, a herald_impl(HeraldImpl) field with HeraldImpl<'_, Point> into point, it's a private field, but will be used to implement Herald.

Second, Define a PointChange type to represent change of Point:

struct PointChange {
    x: Option<Change<f32>>,
    y: Option<Change<f32>>,
}

Third, implement Herald trait for Point by PointChange and herald_impl. Fourth, set_x and set_y method provide on Point, use these method to update Point will be tracked. Fifth, Define a PointState type and impl set_state method to update multi fields at once and change will be tracked.

This example is not tested
PointState {
    x: Option<f32>,
    y: Option<f32>,
}

impl Point {
    fn set_state(&mut self, state: PointState) {
        ...
    }
}

Some field you not want to tracked.

If you want not track some field, you can use skip argument, like

#[herald]
struct Point {
    x: f32,
    #[herald(skip)]
    y: f32,
}

Modules

observable
observer
ops
shared
subject
subscription

Macros

of_sequence

Creates an observable producing a multiple values.

Structs

Change
ChangeEvent
ConnectableObservable
EmptyEmitter
FnEmitter
HeraldImpl

A struct help for some type to implement Herald. Hold it as a field and use it to emit Change, provide change_stream and batched_change_stream.

LocalSubscription
NeverEmitter
ObservableBase
ObserverAll
ObserverComp
ObserverErr
ObserverN
RefChangeEvent
Shared

Shared wrap the Observable, subscribe and accept subscribe in a safe mode by SharedObservable.

SharedSubscription
Subject
Subscriber

Implements the Observer trait and Subscription trait. While the Observer is the public API for consuming the values of an Observable, all Observers get converted to a Subscriber, in order to provide Subscription capabilities.

SubscriptionGuard

An RAII implementation of a "scoped subscribed" of a subscription. When this structure is dropped (falls out of scope), the subscription will be unsubscribed.

SubscriptionWrapper

Wrapper around a subscription which provides the unsubscribe_when_dropped() method.

ThrowEmitter

Enums

Schedulers

Traits

Emitter
Herald
LastChange

A interface for deal with change which from Herald

LocalEmitter
LocalObservable
Observable
Observer

An Observer is a consumer of values delivered by an Observable. One for each type of notification delivered by the Observable: next, error, and complete.

PayloadCopy

There are situations in which rxRust needs to copy items/errors, for example when you use subjects or cloned observables. All items/errors which are copyable (= implement Copy) work in such situations out of the box. Items/errors which implement just Clone but not Copy don't work out of the box (because rxRust wants to prevent you from accidentally introducing poorly performing observable chains). If you have such items/errors, you might want to implement PayloadCopy for them. You can use it just like a marker trait because there's a default method definition which simply calls clone() to make the copy. However, take care to only implement it for types that are cheap to clone! In multi-observer scenarios (e.g. when using subjects), payload_copy() will be called for each single observer!

Publisher
Scheduler

A Scheduler is an object to order task and schedule their execution.

SharedEmitter
SharedObservable
SubscribeAll
SubscribeComplete
SubscribeErr
SubscribeNext
SubscriptionLike

Subscription returns from Observable.subscribe(Subscriber) to allow unsubscribing.

TearDownSize

Functions

create

param subscribe: the function that is called when the Observable is initially subscribed to. This function is given a Subscriber, to which new values can be nexted, or an error method can be called to raise an error, or complete can be called to notify of a successful completion.

delay_task
empty

Creates an observable that produces no values.

from_future

Converts a Future to an observable sequence. Even though if the future poll value has Result::Err type, also emit as a normal value, not trigger to error handle.

from_future_result

Converts a Future to an observable sequence like [from_future@from_future]. But only work for which Future::Output is Result type, and Result::Ok emit to next handle, and Result::Err as an error to handle.

from_iter

Creates an observable that produces values from an iterator.

interval

Creates an observable which will fire at dur time into the future, and will repeat every dur interval after.

interval_at

Creates an observable which will fire at the time specified by at, and then will repeat every dur interval after

never

Creates an observable that never emits anything.

of

Creates an observable producing a single value.

of_fn

Creates an observable that emits the return value of a callable.

of_option

Creates an observable that potentially emits a single value from Option.

of_result

Creates an observable that emits value or the error from a Result given.

repeat

Creates an observable producing same value repeated N times.

throw

Creates an observable that emits no items, just terminates with an error.

Type Definitions

LocalCloneBoxOp
LocalConnectableObservable
LocalSubject
SharedConnectableObservable
SharedSubject

Attribute Macros

herald