diff options
author | Florian Klink <flokli@flokli.de> | 2023-10-14T16·48+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-10-14T17·55+0000 |
commit | 4ae0f428bd207fdf3730d0f6ff73c7410ae9cd7b (patch) | |
tree | 341376899389f822e4bd40b3843aba8954fc77a3 /tvix/nix-compat/src/derivation/write.rs | |
parent | 786b0324a9df1a63606bae72011978fc415f6f07 (diff) |
refactor(tvix/nix-compat): make NixHash an enum with fixed-len bytes r/6807
Less Vec<u8> passed around. Change-Id: Ie153a6bfaa084d7490ffa38634efdf5f3c31a768 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9722 Reviewed-by: Connor Brewster <cbrewster@hey.com> Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/derivation/write.rs')
-rw-r--r-- | tvix/nix-compat/src/derivation/write.rs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/tvix/nix-compat/src/derivation/write.rs b/tvix/nix-compat/src/derivation/write.rs index 9a6234424816..5e1aefa16f06 100644 --- a/tvix/nix-compat/src/derivation/write.rs +++ b/tvix/nix-compat/src/derivation/write.rs @@ -79,22 +79,20 @@ pub fn write_outputs( let mut elements: Vec<&str> = vec![output_name, &output.path]; - let (e2, e3) = match &output.hash_with_mode { - Some(hash) => match hash { - crate::nixhash::NixHashWithMode::Flat(h) => ( - h.algo.to_string(), - data_encoding::HEXLOWER.encode(&h.digest), - ), - crate::nixhash::NixHashWithMode::Recursive(h) => ( - format!("r:{}", h.algo), - data_encoding::HEXLOWER.encode(&h.digest), - ), - }, + let (mode_and_algo, digest) = match &output.hash_with_mode { + Some(crate::nixhash::NixHashWithMode::Flat(h)) => ( + h.algo().to_string(), + data_encoding::HEXLOWER.encode(h.digest_as_bytes()), + ), + Some(crate::nixhash::NixHashWithMode::Recursive(h)) => ( + format!("r:{}", h.algo()), + data_encoding::HEXLOWER.encode(h.digest_as_bytes()), + ), None => ("".to_string(), "".to_string()), }; - elements.push(&e2); - elements.push(&e3); + elements.push(&mode_and_algo); + elements.push(&digest); write_array_elements(writer, &elements)?; |