pub struct StorePath { /* private fields */ }Expand description
Represents a store path which is something that is produced by nix-build.
A store path represents an output in the nix store, matching the pattern
store_dir/hash-name (most often, store_dir will be /nix/store).
Using nix, a store path can be produced by calling nix-build.
Note that even if a store path is a directory, the files inside that directory themselves are not store paths. For example, while the following is a store path:
/nix/store/010yd8jls8w4vcnql4zhjbnyp2yay5pl-bash-4.4-p5while this is not:
/nix/store/010yd8jls8w4vcnql4zhjbnyp2yay5pl-bash-4.4-p5/bin/To avoid any confusion with file paths, we sometimes also refer to a store path as a package.
Implementations§
Source§impl StorePath
impl StorePath
Sourcepub fn parse(origin: PathOrigin, path: &str) -> Option<StorePath>
pub fn parse(origin: PathOrigin, path: &str) -> Option<StorePath>
Parse a store path from an absolute file path.
Since this function does not know where that path comes from, it takes
origin as an argument.
This function returns None if the path could not be parsed as a
store path. You should not rely on that to check whether a path is a store
path though, since it only does minimal validation (for one example, it does
not check the length of the hash).
Sourcepub fn encode(&self) -> Result<Vec<u8>>
pub fn encode(&self) -> Result<Vec<u8>>
Encodes a store path as a sequence of bytes, so that it can be decoded with decode.
The encoding does not use the bytes 0x00 nor 0x01, as long as none of the fields of
this path contain those bytes (this includes store_dir, hash, name and origin).
This is important since it allows the result to be encoded with frcode.
§Panics
The attr and output of the path origin must not contain the byte value 0x02, otherwise
this function panics.
pub fn decode(buf: &[u8]) -> Option<StorePath>
Sourcepub fn name(&self) -> Cow<'_, str>
pub fn name(&self) -> Cow<'_, str>
Returns the name of the store path, which is the part of the file name that
is not the hash. In the above example, it would be bash-4.4-p5.
§Example
use nix_index::package::{PathOrigin, StorePath};
let origin = PathOrigin { attr: "dummy".to_string(), output: "out".to_string(), toplevel: true, system: None };
let store_path = StorePath::parse(origin, "/nix/store/010yd8jls8w4vcnql4zhjbnyp2yay5pl-bash-4.4-p5").unwrap();
assert_eq!(&store_path.name(), "bash-4.4-p5");Sourcepub fn hash(&self) -> Cow<'_, str>
pub fn hash(&self) -> Cow<'_, str>
The hash of the store path. This is the part just before the name of the path.
§Example
use nix_index::package::{PathOrigin, StorePath};
let origin = PathOrigin { attr: "dummy".to_string(), output: "out".to_string(), toplevel: true, system: None };
let store_path = StorePath::parse(origin, "/nix/store/010yd8jls8w4vcnql4zhjbnyp2yay5pl-bash-4.4-p5").unwrap();
assert_eq!(&store_path.name(), "bash-4.4-p5");Sourcepub fn store_dir(&self) -> Cow<'_, str>
pub fn store_dir(&self) -> Cow<'_, str>
The store dir for which this store path was built.
Currently, this will be /nix/store in almost all cases, but
we include it here anyway for completeness.
§Example
use nix_index::package::{PathOrigin, StorePath};
let origin = PathOrigin { attr: "dummy".to_string(), output: "out".to_string(), toplevel: true, system: None };
let store_path = StorePath::parse(origin, "/nix/store/010yd8jls8w4vcnql4zhjbnyp2yay5pl-bash-4.4-p5").unwrap();
assert_eq!(&store_path.store_dir(), "/nix/store");Sourcepub fn as_str(&self) -> Cow<'_, str>
pub fn as_str(&self) -> Cow<'_, str>
Converts the store path back into an absolute path.
§Example
use nix_index::package::{PathOrigin, StorePath};
let origin = PathOrigin { attr: "dummy".to_string(), output: "out".to_string(), toplevel: true, system: None };
let store_path = StorePath::parse(origin, "/nix/store/010yd8jls8w4vcnql4zhjbnyp2yay5pl-bash-4.4-p5").unwrap();
assert_eq!(&store_path.as_str(), "/nix/store/010yd8jls8w4vcnql4zhjbnyp2yay5pl-bash-4.4-p5");Sourcepub fn origin(&self) -> Cow<'_, PathOrigin>
pub fn origin(&self) -> Cow<'_, PathOrigin>
Returns the origin that describes how we discovered this store path.
See the documentation of PathOrigin for more information about this field.
§Example
use nix_index::package::{PathOrigin, StorePath};
let origin = PathOrigin { attr: "dummy".to_string(), output: "out".to_string(), toplevel: true, system: None };
let store_path = StorePath::parse(origin.clone(), "/nix/store/010yd8jls8w4vcnql4zhjbnyp2yay5pl-bash-4.4-p5").unwrap();
assert_eq!(store_path.origin().as_ref(), &origin);Trait Implementations§
Source§impl<'de> Deserialize<'de> for StorePath
impl<'de> Deserialize<'de> for StorePath
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for StorePath
Source§impl Ord for StorePath
impl Ord for StorePath
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for StorePath
impl PartialOrd for StorePath
impl StructuralPartialEq for StorePath
Auto Trait Implementations§
impl Freeze for StorePath
impl RefUnwindSafe for StorePath
impl Send for StorePath
impl Sync for StorePath
impl Unpin for StorePath
impl UnsafeUnpin for StorePath
impl UnwindSafe for StorePath
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.