Created
November 14, 2017 20:55
-
-
Save glandaverde/6b738c0799f6226984a744a3533e3084 to your computer and use it in GitHub Desktop.
Get file extension Rust
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
use std::path::Path; | |
use std::ffi::OsStr; | |
fn main() { | |
fn get_extension_from_filename(filename: &str) -> Option<&str> { | |
Path::new(filename) | |
.extension() | |
.and_then(OsStr::to_str)} | |
assert_eq!(get_extension_from_filename("abc.gz"), Some("gz")); | |
println!("{:?}",get_extension_from_filename("abc.gz")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment