wove/src/lib.rs
2024-10-19 14:14:16 -04:00

58 lines
949 B
Rust

#![feature(async_closure)]
mod aliases;
pub mod fs;
pub mod net;
mod plat;
mod wove;
use aliases::IoResult;
#[cfg(target_os = "linux")]
pub use plat::linux::PlatformLinux as PlatImpl;
use plat::Platform;
pub struct Wove {
platform: PlatImpl,
}
impl Wove {
pub fn new() -> IoResult<Self> {
Ok(Self {
platform: PlatImpl::new(Default::default())?,
})
}
pub async fn run(&self) -> IoResult<()> {
loop {
self.platform.tick().await?;
}
}
}
#[cfg(test)]
mod test {
use std::path::PathBuf;
use crate::Wove;
#[test]
fn sketch() {
let mut wove = Wove::new().unwrap();
let wove = &mut wove;
let fut = async {
let run = async {
wove.run().await?;
Ok("".to_string())
};
let contents = crate::fs::read_to_string(wove, PathBuf::from("src/lib.rs"));
let contents = futures_lite::future::race(run, contents).await;
contents
};
let out = pollster::block_on(fut).unwrap();
assert_eq!(out, "");
}
}