rx_core_subject_behavior

Crates.iorx_core_subject_behavior
lib.rsrx_core_subject_behavior
version0.2.0
created_at2026-01-19 20:56:22.080307+00
updated_at2026-01-24 15:11:11.485216+00
descriptionbehavior_subject for rx_core
homepagehttps://github.com/AlexAegis/rx_bevy
repositoryhttps://github.com/AlexAegis/rx_bevy
max_upload_size
id2055342
size12,630
Sandor (AlexAegis)

documentation

https://github.com/AlexAegis/rx_bevy

README

subject_behavior

crates.io ci codecov license

Always holds a value that is replayed to late subscribers.

See Also

  • PublishSubject - Forwards observed signals to active subscribers without replaying values, but terminal state is replayed.
  • AsyncSubject - Reduces observed values into one and emits it on completion, replaying the result to late subscribers.
  • ReplaySubject - Buffers the last N values and replays them to late subscribers.
  • ProvenanceSubject - BehaviorSubject that also stores an additional filtering value to track provenance.

Example

Run the example with:

cargo run -p rx_core --example subject_behavior_example
use rx_core::prelude::*;

fn main() {
    let mut subject = BehaviorSubject::<i32>::new(10);

    let mut hello_subscription = subject
        .clone()
        .subscribe(PrintObserver::<i32>::new("hello"));

    subject.next(11);

    let _s1 = subject
        .clone()
        .map(|next| next * 2)
        .subscribe(PrintObserver::<i32>::new("hi double"));

    subject.next(12);
    hello_subscription.unsubscribe();
    subject.next(13);
    subject.complete();

    let mut _completed_subscription = subject
        .clone()
        .subscribe(PrintObserver::<i32>::new("hello_completed"));
}

Output:

hello - next: 10
hello - next: 11
hi double - next: 22
hi double - next: 24
hello - next: 12
hello - unsubscribed
hi double - next: 26
hi double - completed
hi double - unsubscribed
hello_completed - next: 13
hello_completed - completed
hello_completed - unsubscribed
Commit count: 652

cargo fmt