ghciwatch/cwd.rs
1use std::path::PathBuf;
2
3use camino::Utf8PathBuf;
4use miette::miette;
5use miette::Context;
6use miette::IntoDiagnostic;
7
8/// Get the current working directory of the process with [`std::env::current_dir`].
9pub fn current_dir() -> miette::Result<PathBuf> {
10 std::env::current_dir()
11 .into_diagnostic()
12 .wrap_err("Failed to get current directory")
13}
14
15/// Get the current working directory of the process as a [`Utf8PathBuf`].
16pub fn current_dir_utf8() -> miette::Result<Utf8PathBuf> {
17 current_dir()?
18 .try_into()
19 .map_err(|path| miette!("Current directory isn't valid UTF-8: {path:?}"))
20}