pub struct ProjectRootId(/* private fields */);Expand description
Stable canonical identity for a project root.
A ProjectRootId is represented by the canonical filesystem path of an
existing project root. Construction uses std::fs::canonicalize, so the
stored path is absolute, has ./../trailing separators collapsed, and has
symlinks resolved.
Git worktrees are first-class roots: this crate does not ask Git for a repository common-dir and does not collapse linked worktrees back to their main checkout. Because a linked worktree has its own checkout directory, the canonical worktree path is a distinct id from the canonical main-checkout path while alternate spellings of either path still converge. A canonical project-root identity.
THE CANONICAL FORM THIS PRODUCES IS A CRYPTOGRAPHIC IDENTITY INPUT IN AT LEAST ONE CONSUMER, WHICH IS NOT VISIBLE FROM THIS CRATE. The vault hashes the canonical directory to derive the keychain service name holding its master key, and to derive the vault id that fences an admin-operation MAC to one vault. A change to canonicalization is therefore a BREAKING CHANGE to those identities.
It does not present as one. The vault looks up a keychain item that does not exist and reports a locked vault over an intact store, or two binaries derive different vault ids and every admin MAC fails verification. Nothing says “these two builds disagree about what this path is” – so the usual reassurance for a path helper, that a mistake surfaces as a loud path mismatch, does not hold here.
The name is the trap: this reads as a path helper and is a canonicalizer for security identities. Route changes to the canonical form past the vault.
Implementations§
Source§impl ProjectRootId
impl ProjectRootId
Sourcepub fn from_path(path: impl AsRef<Path>) -> Result<ProjectRootId, IdentityError>
pub fn from_path(path: impl AsRef<Path>) -> Result<ProjectRootId, IdentityError>
Resolve an existing filesystem path into a canonical project-root id.
Non-existent paths are rejected with IdentityError::NonExistentPath
instead of being logically normalized. That policy avoids silently
aliasing roots whose future meaning could change when missing path
components or symlinks are later created.
That rejection is load-bearing for callers who use it to DETECT a root
that has gone away, so this constructor keeps it. Callers that must still
address a vanished root – ending or inspecting work that was admitted
while the root existed – use Self::from_path_allowing_missing, which
preserves the aliasing guarantee by a narrower means.
Sourcepub fn from_path_allowing_missing(
path: impl AsRef<Path>,
) -> Result<ProjectRootId, IdentityError>
pub fn from_path_allowing_missing( path: impl AsRef<Path>, ) -> Result<ProjectRootId, IdentityError>
Resolve a path into a project-root id even when the path no longer exists.
Resolves the longest prefix that still exists and re-appends the rest,
following any symlink encountered on the missing tail. This is the
behaviour of POSIX realpath on a non-existent path; fs::canonicalize
is the outlier in refusing partial resolution, so this matches a
documented reference rather than inventing a rule.
WHY NOT LEXICAL NORMALIZATION: consumers key durable state on the resolved string. On macOS every temporary directory is reached through a symlink, so a lexically-normalized path is a DIFFERENT string from the id minted while the root existed – the caller would address an empty lineage and receive a confident “no such thing” rather than an error. That is one caller, one spelling, and two ids across time.
WHAT THIS DOES NOT PROMISE: if a missing component later reappears as a
symlink pointing elsewhere, the id moves. Self::from_path does not
prevent that either – it declines to answer while the component is
missing and then resolves through the new link exactly as this does, so
the hazard is shared rather than introduced here. The aliasing guarantee
the strict constructor exists for is preserved by refusing to create NEW
durable state under an id resolved this way; callers admit only
operations that read or end something already recorded.
Sourcepub fn into_path_buf(self) -> PathBuf
pub fn into_path_buf(self) -> PathBuf
Consume the identity and return its canonical path representation.
Trait Implementations§
Source§impl AsRef<Path> for ProjectRootId
impl AsRef<Path> for ProjectRootId
Source§impl Clone for ProjectRootId
impl Clone for ProjectRootId
Source§fn clone(&self) -> ProjectRootId
fn clone(&self) -> ProjectRootId
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ProjectRootId
impl Debug for ProjectRootId
Source§impl Display for ProjectRootId
impl Display for ProjectRootId
impl Eq for ProjectRootId
Source§impl Hash for ProjectRootId
impl Hash for ProjectRootId
Source§impl PartialEq for ProjectRootId
impl PartialEq for ProjectRootId
impl StructuralPartialEq for ProjectRootId
Source§impl TryFrom<&Path> for ProjectRootId
impl TryFrom<&Path> for ProjectRootId
Source§type Error = IdentityError
type Error = IdentityError
Source§fn try_from(
value: &Path,
) -> Result<ProjectRootId, <ProjectRootId as TryFrom<&Path>>::Error>
fn try_from( value: &Path, ) -> Result<ProjectRootId, <ProjectRootId as TryFrom<&Path>>::Error>
Source§impl TryFrom<&str> for ProjectRootId
impl TryFrom<&str> for ProjectRootId
Source§type Error = IdentityError
type Error = IdentityError
Source§fn try_from(
value: &str,
) -> Result<ProjectRootId, <ProjectRootId as TryFrom<&str>>::Error>
fn try_from( value: &str, ) -> Result<ProjectRootId, <ProjectRootId as TryFrom<&str>>::Error>
Source§impl TryFrom<PathBuf> for ProjectRootId
impl TryFrom<PathBuf> for ProjectRootId
Source§type Error = IdentityError
type Error = IdentityError
Source§fn try_from(
value: PathBuf,
) -> Result<ProjectRootId, <ProjectRootId as TryFrom<PathBuf>>::Error>
fn try_from( value: PathBuf, ) -> Result<ProjectRootId, <ProjectRootId as TryFrom<PathBuf>>::Error>
Source§impl TryFrom<String> for ProjectRootId
impl TryFrom<String> for ProjectRootId
Source§type Error = IdentityError
type Error = IdentityError
Source§fn try_from(
value: String,
) -> Result<ProjectRootId, <ProjectRootId as TryFrom<String>>::Error>
fn try_from( value: String, ) -> Result<ProjectRootId, <ProjectRootId as TryFrom<String>>::Error>
Auto Trait Implementations§
impl Forget for ProjectRootId
impl Freeze for ProjectRootId
impl Move for ProjectRootId
impl RefUnwindSafe for ProjectRootId
impl Send for ProjectRootId
impl Sync for ProjectRootId
impl Unpin for ProjectRootId
impl UnsafeUnpin for ProjectRootId
impl UnwindSafe for ProjectRootId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.