about summary refs log tree commit diff
path: root/tvix/nix-compat/src/store_path/mod.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-12-21T14·00+0200
committerflokli <flokli@flokli.de>2023-12-21T16·28+0000
commit91deb67de92c4deaf24ec16c690c4887c796ccff (patch)
tree4ab905394e60881a564dc14da2d29fa54fa1134e /tvix/nix-compat/src/store_path/mod.rs
parentc7ea57df46329084b10e9166b947614f90b04662 (diff)
refactor(nix-compat/store_path): use StorePathRef::to_absolute_path r/7234
Keep the method around in StorePath for convenience, but move the
implementation to StorePathRef.

Change-Id: Ie1844fa01ce6529dc1a58907563c95c3112c831d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10387
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: edef <edef@edef.eu>
Diffstat (limited to 'tvix/nix-compat/src/store_path/mod.rs')
-rw-r--r--tvix/nix-compat/src/store_path/mod.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs
index fa172d1031a2..e23002bfb97e 100644
--- a/tvix/nix-compat/src/store_path/mod.rs
+++ b/tvix/nix-compat/src/store_path/mod.rs
@@ -126,18 +126,18 @@ impl StorePath {
         }
     }
 
-    /// Converts the [StorePath] to an absolute store path string.
+    /// Returns an absolute store path string.
     /// That is just the string representation, prefixed with the store prefix
     /// ([STORE_DIR_WITH_SLASH]),
     pub fn to_absolute_path(&self) -> String {
-        format!("{}{}", STORE_DIR_WITH_SLASH, self)
+        let sp_ref: StorePathRef = self.into();
+        sp_ref.to_absolute_path()
     }
 }
 
 /// Like [StorePath], but without a heap allocation for the name.
 /// Used by [StorePath] for parsing.
 ///
-/// TODO(edef): migrate most methods here
 #[derive(Debug, Eq, PartialEq)]
 pub struct StorePathRef<'a> {
     digest: [u8; DIGEST_SIZE],
@@ -211,6 +211,13 @@ impl<'a> StorePathRef<'a> {
             name: validate_name(&s[ENCODED_DIGEST_SIZE + 1..])?,
         })
     }
+
+    /// Returns an absolute store path string.
+    /// That is just the string representation, prefixed with the store prefix
+    /// ([STORE_DIR_WITH_SLASH]),
+    pub fn to_absolute_path(&self) -> String {
+        format!("{}{}", STORE_DIR_WITH_SLASH, self)
+    }
 }
 
 /// NAME_CHARS contains `true` for bytes that are valid in store path names,
@@ -358,13 +365,12 @@ mod tests {
         let example_nix_path_str =
             "00bgd045z0d4icpbc2yyz4gx48ak44la-net-tools-1.60_p20170221182432";
         let nixpath_expected =
-            StorePath::from_bytes(example_nix_path_str.as_bytes()).expect("must parse");
+            StorePathRef::from_bytes(example_nix_path_str.as_bytes()).expect("must parse");
 
         let nixpath_actual = StorePathRef::from_absolute_path(
             "/nix/store/00bgd045z0d4icpbc2yyz4gx48ak44la-net-tools-1.60_p20170221182432".as_bytes(),
         )
-        .expect("must parse")
-        .to_owned();
+        .expect("must parse");
 
         assert_eq!(nixpath_expected, nixpath_actual);