Skip to content

Commit 9f88c56

Browse files
committed
Rename toybox-msg to toybox-bus; Make MessageBus::poll,poll_consume borrow less
1 parent 95f62e7 commit 9f88c56

File tree

8 files changed

+17
-13
lines changed

8 files changed

+17
-13
lines changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ resolver = "2"
33
members = [
44
"gl",
55
"toybox",
6-
"toybox-host",
7-
"toybox-gfx",
86
"toybox-audio",
9-
"toybox-input",
10-
"toybox-egui",
7+
"toybox-bus",
118
"toybox-cfg",
9+
"toybox-egui",
10+
"toybox-gfx",
11+
"toybox-host",
12+
"toybox-input",
1213
"toybox-vfs",
13-
"toybox-msg",
1414
]
1515

1616
[workspace.package]
@@ -37,7 +37,7 @@ toybox-input = { path = "toybox-input" }
3737
toybox-egui = { path = "toybox-egui" }
3838
toybox-cfg = { path = "toybox-cfg" }
3939
toybox-vfs = { path = "toybox-vfs" }
40-
toybox-msg = { path = "toybox-msg" }
40+
toybox-bus = { path = "toybox-bus" }
4141

4242
gl = { path = "gl" }
4343

toybox-msg/Cargo.toml renamed to toybox-bus/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "toybox-msg"
2+
name = "toybox-bus"
33
version.workspace = true
44
edition.workspace = true
55
authors.workspace = true

toybox-msg/src/lib.rs renamed to toybox-bus/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl MessageBus {
4949
self.count(subscription) > 0
5050
}
5151

52-
pub fn poll<T: Clone + 'static>(&self, subscription: &Subscription<T>) -> impl Iterator<Item=T> + use<'_, T> {
52+
pub fn poll<'sub, T: Clone + 'static>(&self, subscription: &'sub Subscription<T>) -> impl Iterator<Item=T> + use<'sub, T> {
5353
struct Iter<'s, T: Clone + 'static> {
5454
subscription: Rc<SubscriptionInner>,
5555
queue: *mut TypedMessageQueue<T>,
@@ -86,11 +86,11 @@ impl MessageBus {
8686
subscription: subscription.inner.clone(),
8787
queue,
8888
_lock: MessageQueuePollLock::lock(queue),
89-
_phantom: PhantomData,
89+
_phantom: PhantomData::<&'sub ()>,
9090
}
9191
}
9292

93-
pub fn poll_consume<T: 'static>(&self, subscription: &Subscription<T>) -> impl Iterator<Item=T> + use<'_, T> {
93+
pub fn poll_consume<'sub, T: 'static>(&self, subscription: &'sub Subscription<T>) -> impl Iterator<Item=T> + use<'sub, T> {
9494
struct Iter<'s, T: 'static> {
9595
subscription: Rc<SubscriptionInner>,
9696
queue: *mut TypedMessageQueue<T>,
@@ -130,7 +130,7 @@ impl MessageBus {
130130
subscription: subscription.inner.clone(),
131131
queue,
132132
lock: MessageQueuePollLock::lock(queue),
133-
_phantom: PhantomData,
133+
_phantom: PhantomData::<&'sub ()>,
134134
}
135135
}
136136

File renamed without changes.

toybox/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ toybox-input.workspace = true
1313
toybox-egui.workspace = true
1414
toybox-cfg.workspace = true
1515
toybox-vfs.workspace = true
16-
toybox-msg.workspace = true
16+
toybox-bus.workspace = true
1717

1818

1919
common.workspace = true

toybox/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub struct Context {
77
pub egui: egui::Context,
88
pub cfg: cfg::Config,
99
pub vfs: vfs::Vfs,
10+
pub bus: bus::MessageBus,
1011

1112
pub(super) egui_integration: egui_backend::Integration,
1213

@@ -25,6 +26,7 @@ impl Context {
2526
pub(crate) fn prepare_frame(&mut self) {
2627
self.audio.update();
2728
self.input.reset_tracker();
29+
self.bus.garbage_collect();
2830
}
2931

3032
// Called after events are processed, immediately before control is passed to the app.

toybox/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub fn run_with_settings<F, A>(settings: host::Settings<'_>, start_app: F) -> an
5353

5454
gfx.resize(backbuffer_size);
5555

56+
let bus = bus::MessageBus::new();
5657
let input = input::System::new(host.window.clone());
5758

5859
let egui = egui::Context::default();
@@ -65,6 +66,7 @@ pub fn run_with_settings<F, A>(settings: host::Settings<'_>, start_app: F) -> an
6566
egui,
6667
cfg,
6768
vfs,
69+
bus,
6870

6971
egui_integration,
7072
egui_claiming_input_gate: Gate::new(),

toybox/src/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub use toybox_audio as audio;
1010
pub use toybox_input as input;
1111
pub use toybox_egui as egui_backend;
1212
pub use toybox_vfs as vfs;
13-
pub use toybox_msg as msg;
13+
pub use toybox_bus as bus;
1414

1515
pub use host::prelude::*;
1616
pub use gfx::prelude::*;

0 commit comments

Comments
 (0)