1
0
Fork 0
forked from wry/wry

it: test window gains kb focus when mapped

This commit is contained in:
Julian Orth 2022-05-04 14:36:18 +02:00
parent cbf539cbcc
commit c827a93dbb
19 changed files with 672 additions and 39 deletions

26
src/utils/once.rs Normal file
View file

@ -0,0 +1,26 @@
#![allow(dead_code)]
use std::{cell::Cell, future::Future};
#[derive(Default)]
pub struct Once {
done: Cell<bool>,
}
impl Once {
pub fn set(&self) -> bool {
!self.done.replace(true)
}
pub fn exec<F: FnOnce()>(&self, f: F) {
if !self.done.replace(true) {
f();
}
}
pub async fn exec_async<G: Future<Output = ()>, F: FnOnce() -> G>(&self, f: F) {
if !self.done.replace(true) {
f().await;
}
}
}