From e32c2070e4cf66d5a02ff024324aecc75fc520fd Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 18 Nov 2023 15:45:05 +0200 Subject: refactor(tvix/nix-compat): no impl > 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 Reviewed-by: raitobezarius Tested-by: BuildkiteCI --- tvix/nix-compat/src/store_path/mod.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'tvix') 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 { - 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> 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 { -- cgit 1.4.1