refactor(tvix/nix-compat): no impl <StorePathRef<'_>> for StorePath

This suggests it's cheap to convert around, but name actually does
allocate.

Move to a `to_owned(&self) -> StorePath`, to better signal that this
does allocate.

Change-Id: Ifaf7c21599e2a467d06e2b4ae1364228370275db
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10066
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2023-11-18 15:45:05 +02:00 committed by flokli
parent df63b719ac
commit e32c2070e4

View file

@ -94,7 +94,7 @@ impl StorePath {
/// Construct a [StorePath] by passing the `$digest-$name` string
/// that comes after [STORE_DIR_WITH_SLASH].
pub fn from_bytes(s: &[u8]) -> Result<StorePath, Error> {
Ok(StorePathRef::from_bytes(s)?.into())
Ok(StorePathRef::from_bytes(s)?.to_owned())
}
/// Construct a [StorePath] from an absolute store path string.
@ -162,15 +162,6 @@ pub struct StorePathRef<'a> {
name: &'a str,
}
impl From<StorePathRef<'_>> for StorePath {
fn from(StorePathRef { digest, name }: StorePathRef<'_>) -> Self {
StorePath {
digest,
name: name.to_owned(),
}
}
}
impl<'a> From<&'a StorePath> for StorePathRef<'a> {
fn from(&StorePath { digest, ref name }: &'a StorePath) -> Self {
StorePathRef {
@ -189,6 +180,13 @@ impl<'a> StorePathRef<'a> {
self.name
}
pub fn to_owned(&self) -> StorePath {
StorePath {
digest: self.digest,
name: self.name.to_owned(),
}
}
/// Construct a [StorePathRef] by passing the `$digest-$name` string
/// that comes after [STORE_DIR_WITH_SLASH].
pub fn from_bytes(s: &'a [u8]) -> Result<Self, Error> {