about summary refs log tree commit diff
path: root/tvix/nix-compat/src/store_path
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-11-18T13·45+0200
committerflokli <flokli@flokli.de>2023-11-18T19·37+0000
commite32c2070e4cf66d5a02ff024324aecc75fc520fd (patch)
tree8cf2b8c66eaa2e0b7ca968bdc6a96dd73cbaff1a /tvix/nix-compat/src/store_path
parentdf63b719ac4ce4d1944295c634ec73da14ae72e7 (diff)
refactor(tvix/nix-compat): no impl <StorePathRef<'_>> for StorePath r/7028
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
Diffstat (limited to 'tvix/nix-compat/src/store_path')
-rw-r--r--tvix/nix-compat/src/store_path/mod.rs18
1 files changed, 8 insertions, 10 deletions
diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs
index 3eb8877d6efd..c54ed3710123 100644
--- a/tvix/nix-compat/src/store_path/mod.rs
+++ b/tvix/nix-compat/src/store_path/mod.rs
@@ -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> {