mod tests;
use std::{
+ fmt,
fs::{self, read_dir, ReadDir},
io,
process::Command,
};
-use anyhow::{bail, format_err, Context, Result};
+use anyhow::{bail, format_err, Context};
use paths::{AbsPath, AbsPathBuf};
use rustc_hash::FxHashSet;
}
impl ProjectManifest {
- pub fn from_manifest_file(path: AbsPathBuf) -> Result<ProjectManifest> {
+ pub fn from_manifest_file(path: AbsPathBuf) -> anyhow::Result<ProjectManifest> {
let path = ManifestPath::try_from(path)
- .map_err(|path| format_err!("bad manifest path: {}", path.display()))?;
+ .map_err(|path| format_err!("bad manifest path: {path}"))?;
if path.file_name().unwrap_or_default() == "rust-project.json" {
return Ok(ProjectManifest::ProjectJson(path));
}
if path.file_name().unwrap_or_default() == "Cargo.toml" {
return Ok(ProjectManifest::CargoToml(path));
}
- bail!("project root must point to Cargo.toml or rust-project.json: {}", path.display());
+ bail!("project root must point to Cargo.toml or rust-project.json: {path}");
}
- pub fn discover_single(path: &AbsPath) -> Result<ProjectManifest> {
+ pub fn discover_single(path: &AbsPath) -> anyhow::Result<ProjectManifest> {
let mut candidates = ProjectManifest::discover(path)?;
let res = match candidates.pop() {
None => bail!("no projects"),
}
}
-fn utf8_stdout(mut cmd: Command) -> Result<String> {
+impl fmt::Display for ProjectManifest {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ ProjectManifest::ProjectJson(it) | ProjectManifest::CargoToml(it) => {
+ fmt::Display::fmt(&it, f)
+ }
+ }
+ }
+}
+
+fn utf8_stdout(mut cmd: Command) -> anyhow::Result<String> {
let output = cmd.output().with_context(|| format!("{cmd:?} failed"))?;
if !output.status.success() {
match String::from_utf8(output.stderr) {