std-module
std::os::unix: work with native path bytes
Unix native strings can hold non-UTF-8 bytes. OsStrExt exposes the Unix representation; use it only in Unix-specific code, and do not assume Windows has the same encoding. The fallback keeps the example buildable elsewhere; it does not test Unix behavior on those platforms. Fixture: Expected stdout (not executed): native string branch complete Expected stderr: (empty) Expected exit: 0 Common mistake: Converting all filenames to UTF-8 before opening them.
Formal Syntax & Structure
rust syntaxrust
std::os::unix::ffi::OsStrExt::as_bytesWorking Example
Example Snippetrust
fn main() { #[cfg(unix)] { use std::{ffi::OsStr, os::unix::ffi::OsStrExt}; let name = OsStr::from_bytes(b"item\xff"); assert!(name.to_str().is_none()); assert_eq!(name.as_bytes(), b"item\xff"); } println!("native string branch complete");}