Function git_url::expand_path::parse

source ·
pub fn parse(path: &BStr) -> Result<(Option<ForUser>, BString), Error>
Expand description

Parse user information from the given path, returning (possible user information, adjusted input path).

Supported formats for user extraction are…

  • ~/repopath - the currently logged in user’s home.
  • ~user/repopath - the repository in the given user’s home.
Examples found in repository?
src/expand_path.rs (line 77)
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
pub fn for_shell(path: BString) -> BString {
    use bstr::ByteVec;
    match parse(path.as_slice().as_bstr()) {
        Ok((user, mut path)) => match user {
            Some(ForUser::Current) => {
                path.insert(0, b'~');
                path
            }
            Some(ForUser::Name(mut user)) => {
                user.insert(0, b'~');
                user.append(path.as_vec_mut());
                user
            }
            None => path,
        },
        Err(_) => path,
    }
}