Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Dec 11, 2023
1 parent 1c112a1 commit 2c93ed2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ fn main() {

a.set(2);

for _ in 0..3 {
Runtime::current().run();
for _ in 0..2 {
Runtime::current().run();
}
}
Expand Down
3 changes: 1 addition & 2 deletions examples/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ fn main() {

a.set(2);

for _ in 0..3 {
Runtime::current().run();
for _ in 0..2 {
Runtime::current().run();
}
}
28 changes: 3 additions & 25 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub use rt::Runtime;
mod signal;
pub use self::signal::Signal;

mod slot;
pub use self::slot::Slot;

pub struct Window {}

#[object]
Expand Down Expand Up @@ -70,28 +73,3 @@ impl App {
});
}
}

pub trait Slot<O, D> {
fn handle(&mut self, object: &mut O, data: D);
}

macro_rules! impl_slot {
($($t:tt),*) => {
impl<F: Fn(&mut O, $($t),*,), O, $($t),*> Slot<O, ($($t),*,)> for F {
fn handle(&mut self, object: &mut O, data: ($($t),*,)) {
#[allow(non_snake_case)]
let ($($t),*,) = data;
self(object, $($t),*)
}
}
};
}

impl_slot!(T1);
impl_slot!(T1, T2);
impl_slot!(T1, T2, T3);
impl_slot!(T1, T2, T3, T4);
impl_slot!(T1, T2, T3, T4, T5);
impl_slot!(T1, T2, T3, T4, T5, T6);
impl_slot!(T1, T2, T3, T4, T5, T6, T7);
impl_slot!(T1, T2, T3, T4, T5, T6, T7, T8);
24 changes: 24 additions & 0 deletions src/slot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pub trait Slot<O, D> {
fn handle(&mut self, object: &mut O, data: D);
}

macro_rules! impl_slot {
($($t:tt),*) => {
impl<F: Fn(&mut O, $($t),*,), O, $($t),*> Slot<O, ($($t),*,)> for F {
fn handle(&mut self, object: &mut O, data: ($($t),*,)) {
#[allow(non_snake_case)]
let ($($t),*,) = data;
self(object, $($t),*)
}
}
};
}

impl_slot!(T1);
impl_slot!(T1, T2);
impl_slot!(T1, T2, T3);
impl_slot!(T1, T2, T3, T4);
impl_slot!(T1, T2, T3, T4, T5);
impl_slot!(T1, T2, T3, T4, T5, T6);
impl_slot!(T1, T2, T3, T4, T5, T6, T7);
impl_slot!(T1, T2, T3, T4, T5, T6, T7, T8);

0 comments on commit 2c93ed2

Please sign in to comment.