#![allow(unused_imports, unused_variables, dead_code)] use std::{future::Future, sync::Mutex, task::Poll}; pub(crate) fn model(f: F) where F: Fn() + Sync + Send + 'static, { #[cfg(not(loom))] f(); #[cfg(loom)] loom::model(f); } pub(crate) mod thread { #[cfg(not(loom))] pub(crate) use std::thread::{spawn, yield_now}; #[cfg(loom)] pub(crate) use loom::thread::{spawn, yield_now}; } pub fn run(f: F) -> ::Output { use std::task::Context; let mut f = Box::pin(f); let waker = futures::task::noop_waker(); let mut cx = Context::from_waker(&waker); loop { match f.as_mut().poll(&mut cx) { Poll::Ready(v) => return v, Poll::Pending => thread::yield_now(), } } } pub fn strip(str: impl AsRef) -> String { let re = regex::Regex::new(r":\d+:\d+").unwrap(); re.replace_all(str.as_ref(), ":LINE:COL").to_string() } pub fn defer R, R>(f: F) -> impl Drop { Defer(Some(f)) } struct Defer R, R>(Option); impl R, R> Drop for Defer { fn drop(&mut self) { self.0.take().unwrap()(); } }