std-method
Path text conversion: to_str and to_string_lossy
Use a native path for filesystem calls. UTF-8 conversion can fail, and lossy display may replace invalid data; do not use the display form as a unique filename key. Expected stdout (not executed): true گزارش.txt Common mistake: Reconstructing a native path from a lossy display string.
Formal Syntax & Structure
rust syntaxrust
path.to_str() -> Option<&str>; path.to_string_lossy() -> Cow<str>Working Example
Example Snippetrust
fn main() { use std::path::Path; let p = Path::new("گزارش.txt"); println!("{} {}", p.to_str().is_some(), p.to_string_lossy());}