pub struct StorePath { /* private fields */ }Expand description
A path in the Nix store.
Represents a store path that can be realized or queried.
Implementations§
Source§impl StorePath
impl StorePath
Sourcepub fn name(&self) -> Result<String>
pub fn name(&self) -> Result<String>
Get the name component of the store path.
Returns the name part of the store path (everything after the hash).
For example, for "/nix/store/abc123...-hello-1.0" this returns
"hello-1.0".
§Errors
Returns an error if the name cannot be retrieved.
Sourcepub fn hash_part(&self) -> Result<[u8; 20]>
pub fn hash_part(&self) -> Result<[u8; 20]>
Get the hash component of the store path as raw bytes.
The 20-byte hash is decoded from the “nix32” encoding
in the store path. For example, for
"/nix/store/abc123...-hello-1.0" this returns the raw
hash bytes corresponding to "abc123...".
§Returns
The raw 20-byte hash.
§Errors
Returns an error if the hash cannot be retrieved.
Sourcepub fn from_parts(
context: &Arc<Context>,
hash: &[u8; 20],
name: &str,
) -> Result<Self>
pub fn from_parts( context: &Arc<Context>, hash: &[u8; 20], name: &str, ) -> Result<Self>
Create a StorePath from its constituent hash and name parts.
Unlike parse, this does not require a Store
reference or the /nix/store prefix.
§Arguments
hash- The 20-byte raw hash (as produced byhash_part).name- The name component (e.g.,"hello-1.0").
§Returns
A new StorePath.
§Errors
Returns an error if the path cannot be created.
Trait Implementations§
Source§impl Display for StorePath
Renders the name component only (e.g. hello-1.0), not the canonical
/nix/store/<hash>-<name> string.
impl Display for StorePath
Renders the name component only (e.g. hello-1.0), not the canonical
/nix/store/<hash>-<name> string.
The Nix C API does not expose a store-directory-aware print function;
without a Store handle there is no way to recover the full path. Use
Store::print_path (requires the shim feature) when you need the
canonical form.