| Crates.io | rx_core_subject_behavior |
| lib.rs | rx_core_subject_behavior |
| version | 0.2.0 |
| created_at | 2026-01-19 20:56:22.080307+00 |
| updated_at | 2026-01-24 15:11:11.485216+00 |
| description | behavior_subject for rx_core |
| homepage | https://github.com/AlexAegis/rx_bevy |
| repository | https://github.com/AlexAegis/rx_bevy |
| max_upload_size | |
| id | 2055342 |
| size | 12,630 |
Always holds a value that is replayed to late subscribers.
N values and replays them to late subscribers.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