1
0
Fork 0
forked from wry/wry

all: split reusable components into workspace crates

This commit is contained in:
kossLAN 2026-05-29 09:14:53 -04:00
parent 2a079ed800
commit 657e7ce2f7
No known key found for this signature in database
225 changed files with 7422 additions and 17602 deletions

44
utils/src/on_change.rs Normal file
View file

@ -0,0 +1,44 @@
use {
crate::{clonecell::CloneCell, syncqueue::SyncQueue},
std::{
fmt::{Debug, Formatter},
rc::Rc,
},
};
pub struct OnChange<T> {
pub on_change: CloneCell<Option<Rc<dyn Fn()>>>,
pub events: SyncQueue<T>,
}
impl<T> OnChange<T> {
pub fn clear(&self) {
self.on_change.take();
self.events.take();
}
pub fn send_event(&self, event: T) {
self.events.push(event);
if let Some(cb) = self.on_change.get() {
cb();
}
}
}
impl<T> Default for OnChange<T> {
fn default() -> Self {
Self {
on_change: Default::default(),
events: Default::default(),
}
}
}
impl<T> Debug for OnChange<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self.on_change.get() {
None => f.write_str("None"),
Some(_) => f.write_str("Some"),
}
}
}