expression

Distinguish Windows handles from Unix descriptors

Windows file handles are not Unix integer descriptors. OwnedHandle owns a handle closed through CloseHandle; BorrowedHandle provides lifetime-bound access. This applies only to resources with the matching close contract, not registry keys or sockets. The Windows-only fixture uses safe File conversions; the Linux runner skips it. Expected stdout (not executed): handle owned Common mistake: Using a Unix raw descriptor API on Windows or assuming every native handle is closed the same way. Run only in the isolated fixture runner, not a public code playground.

Formal Syntax & Structure

rust syntaxrust
std::os::windows::io::{AsHandle, OwnedHandle}

Working Example

Example Snippetrust
use std::{fs::{self, File, OpenOptions}, io::{self, Write}, os::windows::io::{AsHandle, OwnedHandle}};fn main() -> io::Result<()> {    let file = OpenOptions::new().write(true).create_new(true).open("handle.txt")?;    let owned: OwnedHandle = file.into();    { let _borrowed = owned.as_handle(); }    let mut file: File = owned.into(); file.write_all(b"handle owned")?; drop(file);    println!("{}", fs::read_to_string("handle.txt")?); Ok(())}
Rust Reference