Created
July 28, 2016 16:49
-
-
Save anonymous/134f8b5a85222470f5986c93e44a26a1 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
use std::str; | |
use std::path::Path; | |
println!("{:?}", "/tmp/bar/foo.txt".as_bytes()); | |
//let buf = "/tmp/bar/foo.txt".as_bytes(); | |
let buf = "C:/temp/foo/bar/foo.txt".as_bytes(); | |
let buf_string = str::from_utf8(buf).unwrap(); | |
//let path = Path::new("/tmp/foo/bar.txt"); | |
let path = Path::new(buf_string); | |
let file = path.file_name(); | |
let extension = path.extension(); | |
let parent_dir = path.parent(); | |
println!("file: {:?} ext: {:?} parent:{:?}", file, extension, parent_dir); | |
use std::path::PathBuf; | |
let mut path = PathBuf::from("c:\\"); | |
path.push("windows"); | |
path.push("system32"); | |
path.set_extension("dll"); | |
println!("{:?}", path.into_os_string()); | |
} | |
#[allow(dead_code)] | |
fn unicode() { | |
let chars = ['日', '本', '国', '대', '한', '민']; | |
for &c in &chars { | |
let escaped = c.escape_unicode().collect::<String>(); | |
let charcode = u32::from_str_radix(&escaped[3..7], 16).unwrap(); | |
println!("{} -> {} -> {} -> {} -> {}", | |
c, | |
escaped, | |
charcode, | |
std::char::from_u32(charcode).unwrap(), | |
&escaped[3..7]); | |
} | |
println!("{}", | |
std::char::from_u32(u32::from_str_radix("2691", 16).unwrap()).unwrap()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment