1 //! See [`ManifestPath`].
2 use std::{ops, path::Path};
4 use paths::{AbsPath, AbsPathBuf};
6 /// More or less [`AbsPathBuf`] with non-None parent.
8 /// We use it to store path to Cargo.toml, as we frequently use the parent dir
9 /// as a working directory to spawn various commands, and its nice to not have
10 /// to `.unwrap()` everywhere.
12 /// This could have been named `AbsNonRootPathBuf`, as we don't enforce that
13 /// this stores manifest files in particular, but we only use this for manifests
14 /// at the moment in practice.
15 #[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
16 pub struct ManifestPath {
20 impl TryFrom<AbsPathBuf> for ManifestPath {
21 type Error = AbsPathBuf;
23 fn try_from(file: AbsPathBuf) -> Result<Self, Self::Error> {
24 if file.parent().is_none() {
27 Ok(ManifestPath { file })
33 // Shadow `parent` from `Deref`.
34 pub fn parent(&self) -> &AbsPath {
35 self.file.parent().unwrap()
39 impl ops::Deref for ManifestPath {
40 type Target = AbsPath;
42 fn deref(&self) -> &Self::Target {
47 impl AsRef<Path> for ManifestPath {
48 fn as_ref(&self) -> &Path {