`path` with the home directory shown as `~`, so a pasted report does not carry the user's account name. The part after `~` is joined with `/` on every platform, so Windows never renders a mixed `~/.x\settings.json`.
(path: &Path, home: Option<&Path>)
| 1364 | /// carry the user's account name. The part after `~` is joined with `/` on |
| 1365 | /// every platform, so Windows never renders a mixed `~/.x\settings.json`. |
| 1366 | fn display_path(path: &Path, home: Option<&Path>) -> String { |
| 1367 | let canonical_home = home.and_then(|home| home.canonicalize().ok()); |
| 1368 | let relative = home |
| 1369 | .and_then(|home| path.strip_prefix(home).ok()) |
| 1370 | .or_else(|| { |
| 1371 | canonical_home |
| 1372 | .as_deref() |
| 1373 | .and_then(|home| path.strip_prefix(home).ok()) |
| 1374 | }); |
| 1375 | match relative { |
| 1376 | Some(rest) if rest.as_os_str().is_empty() => "~".to_string(), |
| 1377 | Some(rest) => { |
| 1378 | let parts: Vec<_> = rest |
| 1379 | .components() |
| 1380 | .map(|part| part.as_os_str().to_string_lossy()) |
| 1381 | .collect(); |
| 1382 | format!("~/{}", parts.join("/")) |
| 1383 | } |
| 1384 | None => path.display().to_string(), |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | #[cfg(test)] |
| 1389 | mod tests { |
no test coverage detected