Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

get file extension

  • Path
  • extension
use std::path::Path;

fn main() {
    let path = Path::new("a/b/code.rs");
    println!("{:?}", path.extension().unwrap());
    println!("{:?}", path.extension().unwrap() == "rs");

    let path = Path::new("a/b/code");
    match path.extension() {
        Some(value) => println!("{:?}", value),
        None => println!("Has no extension"),
    };
}