std-module

std::os::windows: inspect wide native strings

Windows extensions expose native wide string units. encode_wide yields u16 units without an automatic terminating zero. This is not a request to call a foreign API; it demonstrates why native paths should not be reduced to a universal byte encoding. On non-Windows targets the example skips the platform-specific assertions. Fixture: Expected stdout (not executed): native string branch complete Expected stderr: (empty) Expected exit: 0 Common mistake: Assuming encode_wide appends a NUL or that all native strings are valid Unicode.

Formal Syntax & Structure

rust syntaxrust
std::os::windows::ffi::OsStrExt::encode_wide

Working Example

Example Snippetrust
fn main() {    #[cfg(windows)]    {        use std::{ffi::OsStr, os::windows::ffi::OsStrExt};        let units: Vec<u16> = OsStr::new("AB").encode_wide().collect();        assert_eq!(units, vec![65, 66]);    }    println!("native string branch complete");}
Rust Reference