llam 0.1.4

Safe, Go-style Rust bindings for the LLAM runtime
#[cfg(windows)]
fn main() -> llam::Result<()> {
    use std::fs::OpenOptions;
    use std::os::windows::fs::OpenOptionsExt;
    use std::os::windows::io::AsRawHandle;

    const FILE_FLAG_OVERLAPPED: u32 = 0x40000000;

    let path = std::env::temp_dir().join(format!("llam-rs-handle-{}.tmp", std::process::id()));
    let file = OpenOptions::new()
        .read(true)
        .write(true)
        .create(true)
        .truncate(true)
        .custom_flags(FILE_FLAG_OVERLAPPED)
        .open(&path)
        .map_err(llam::Error::from)?;

    let handle_value = file.as_raw_handle() as usize;
    let result = llam::Runtime::builder()
        .profile(llam::Profile::IoLatency)
        .run(move || {
            let handle = handle_value as llam::io::Handle;

            let written = llam::io::write_handle(handle, b"ping").map_err(llam::Error::from)?;
            assert_eq!(written, 4);

            let mut buf = [0u8; 4];
            let read = llam::io::read_handle(handle, &mut buf).map_err(llam::Error::from)?;
            assert_eq!(read, 4);
            assert_eq!(&buf, b"ping");
            Ok(())
        });

    let _ = std::fs::remove_file(&path);
    result
}

#[cfg(not(windows))]
fn main() {
    println!("windows_handle_io is Windows-only");
}