Skip to main content

ProjectRootId

Struct ProjectRootId 

Source
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

Source

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.

Source

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.

Source

pub fn as_path(&self) -> &Path

Borrow the canonical path backing this identity.

Source

pub fn into_path_buf(self) -> PathBuf

Consume the identity and return its canonical path representation.

Trait Implementations§

Source§

impl AsRef<Path> for ProjectRootId

Source§

fn as_ref(&self) -> &Path

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for ProjectRootId

Source§

fn clone(&self) -> ProjectRootId

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProjectRootId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for ProjectRootId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for ProjectRootId

Source§

impl Hash for ProjectRootId

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ProjectRootId

Source§

fn eq(&self, other: &ProjectRootId) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ProjectRootId

Source§

impl TryFrom<&Path> for ProjectRootId

Source§

type Error = IdentityError

The type returned in the event of a conversion error.
Source§

fn try_from( value: &Path, ) -> Result<ProjectRootId, <ProjectRootId as TryFrom<&Path>>::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for ProjectRootId

Source§

type Error = IdentityError

The type returned in the event of a conversion error.
Source§

fn try_from( value: &str, ) -> Result<ProjectRootId, <ProjectRootId as TryFrom<&str>>::Error>

Performs the conversion.
Source§

impl TryFrom<PathBuf> for ProjectRootId

Source§

type Error = IdentityError

The type returned in the event of a conversion error.
Source§

fn try_from( value: PathBuf, ) -> Result<ProjectRootId, <ProjectRootId as TryFrom<PathBuf>>::Error>

Performs the conversion.
Source§

impl TryFrom<String> for ProjectRootId

Source§

type Error = IdentityError

The type returned in the event of a conversion error.
Source§

fn try_from( value: String, ) -> Result<ProjectRootId, <ProjectRootId as TryFrom<String>>::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more