text: render text asynchronously
This commit is contained in:
parent
d9eb14e2bc
commit
12f358c0d9
12 changed files with 893 additions and 421 deletions
18
src/utils/on_drop_event.rs
Normal file
18
src/utils/on_drop_event.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use {crate::utils::asyncevent::AsyncEvent, std::rc::Rc};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct OnDropEvent {
|
||||
ae: Rc<AsyncEvent>,
|
||||
}
|
||||
|
||||
impl OnDropEvent {
|
||||
pub fn event(&self) -> Rc<AsyncEvent> {
|
||||
self.ae.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for OnDropEvent {
|
||||
fn drop(&mut self) {
|
||||
self.ae.trigger()
|
||||
}
|
||||
}
|
||||
|
|
@ -201,13 +201,20 @@ impl<K: Eq, V, const N: usize> SmallMapMut<K, V, N> {
|
|||
pub fn get_or_default_mut(&mut self, k: K) -> &mut V
|
||||
where
|
||||
V: Default,
|
||||
{
|
||||
self.get_or_insert_with(k, || V::default())
|
||||
}
|
||||
|
||||
pub fn get_or_insert_with<F>(&mut self, k: K, f: F) -> &mut V
|
||||
where
|
||||
F: FnOnce() -> V,
|
||||
{
|
||||
for (ek, ev) in &mut self.m {
|
||||
if ek == &k {
|
||||
return unsafe { (ev as *mut V).deref_mut() };
|
||||
}
|
||||
}
|
||||
self.m.push((k, V::default()));
|
||||
self.m.push((k, f()));
|
||||
&mut self.m.last_mut().unwrap().1
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue