From 3f856d897713aca25156cc7d471c54845367bfb6 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 30 Jul 2023 09:35:34 +0200 Subject: refactor(tvix/nix-compat/derivation): generic write_array_elements We're happy with any &[S], as long as . This allows passing both strings and &[u8]. Change-Id: If2a80d9b1ee33ba328c9cdab4fa83ca7b98a71e2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8994 Autosubmit: flokli Reviewed-by: raitobezarius Tested-by: BuildkiteCI --- tvix/nix-compat/src/derivation/write.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'tvix') diff --git a/tvix/nix-compat/src/derivation/write.rs b/tvix/nix-compat/src/derivation/write.rs index 464b02fef149..22985fb4b55f 100644 --- a/tvix/nix-compat/src/derivation/write.rs +++ b/tvix/nix-compat/src/derivation/write.rs @@ -48,7 +48,10 @@ pub(crate) fn write_field>( Ok(()) } -fn write_array_elements(writer: &mut impl Write, elements: &[BString]) -> Result<(), io::Error> { +fn write_array_elements>( + writer: &mut impl Write, + elements: &[S], +) -> Result<(), io::Error> { for (index, element) in elements.iter().enumerate() { if index > 0 { write_char(writer, COMMA)?; @@ -70,29 +73,26 @@ pub fn write_outputs( write_char(writer, COMMA)?; } - let mut elements: Vec = vec![ - output_name.as_bytes().to_vec().into(), - output.path.as_bytes().to_vec().into(), - ]; + write_char(writer, PAREN_OPEN)?; + + 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().as_bytes().to_vec(), - data_encoding::HEXLOWER.encode(&h.digest).as_bytes().into(), + h.algo.to_string(), + data_encoding::HEXLOWER.encode(&h.digest), ), crate::nixhash::NixHashWithMode::Recursive(h) => ( - format!("r:{}", h.algo).as_bytes().to_vec(), - data_encoding::HEXLOWER.encode(&h.digest).as_bytes().into(), + format!("r:{}", h.algo), + data_encoding::HEXLOWER.encode(&h.digest), ), }, - None => (vec![], vec![]), + None => ("".to_string(), "".to_string()), }; - elements.push(e2.into()); - elements.push(e3.into()); - - write_char(writer, PAREN_OPEN)?; + elements.push(&e2); + elements.push(&e3); write_array_elements(writer, &elements)?; -- cgit 1.4.1