diff options
author | Florian Klink <flokli@flokli.de> | 2023-07-30T07·35+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-07-31T21·50+0000 |
commit | 3f856d897713aca25156cc7d471c54845367bfb6 (patch) | |
tree | 84dd45a7b0b9149c4435a9dcd33afb2be3f7e040 /tvix/nix-compat/src/derivation | |
parent | 34b7620764247bb967062a94c06a1750f8069701 (diff) |
refactor(tvix/nix-compat/derivation): generic write_array_elements r/6451
We're happy with any &[S], as long as <S: AsRef<[u8]>. This allows passing both strings and &[u8]. Change-Id: If2a80d9b1ee33ba328c9cdab4fa83ca7b98a71e2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8994 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/derivation')
-rw-r--r-- | tvix/nix-compat/src/derivation/write.rs | 28 |
1 files changed, 14 insertions, 14 deletions
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<S: AsRef<[u8]>>( Ok(()) } -fn write_array_elements(writer: &mut impl Write, elements: &[BString]) -> Result<(), io::Error> { +fn write_array_elements<S: AsRef<[u8]>>( + 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<BString> = 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)?; |