native-dialog 0.9.6

A library to display dialogs. Supports GNU/Linux, BSD Unix, macOS and Windows.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::path::{Component, Path, PathBuf};

use dirs::home_dir;

pub fn resolve_tilde<P: AsRef<Path> + ?Sized>(path: &P) -> Option<PathBuf> {
    let mut result = PathBuf::new();

    let mut components = path.as_ref().components();
    match components.next() {
        Some(Component::Normal(c)) if c == "~" => result.push(home_dir()?),
        Some(c) => result.push(c),
        None => {}
    };
    result.extend(components);

    Some(result)
}