refactor(nix-compat/derivation): make write_environment more generic

We don't actually care if it's a BTreeMap of strings, bstrings or any of
that sort.

The only thing we want to be able to do is get a reference to the bytes
from the keys and values.

Change-Id: I21b85811a9ea47fe06afa3108836ef9295e5d89b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9737
Tested-by: BuildkiteCI
Reviewed-by: edef <edef@edef.eu>
This commit is contained in:
Florian Klink 2023-10-15 09:07:21 +01:00 committed by flokli
parent f337601f69
commit 9aafbe8d95

View file

@ -174,13 +174,15 @@ pub fn write_arguments(writer: &mut impl Write, arguments: &[String]) -> Result<
Ok(()) Ok(())
} }
pub fn write_enviroment( pub fn write_enviroment<E, K, V>(writer: &mut impl Write, environment: E) -> Result<(), io::Error>
writer: &mut impl Write, where
environment: &BTreeMap<String, BString>, E: IntoIterator<Item = (K, V)>,
) -> Result<(), io::Error> { K: AsRef<[u8]>,
V: AsRef<[u8]>,
{
write_char(writer, BRACKET_OPEN)?; write_char(writer, BRACKET_OPEN)?;
for (i, (k, v)) in environment.iter().enumerate() { for (i, (k, v)) in environment.into_iter().enumerate() {
if i > 0 { if i > 0 {
write_char(writer, COMMA)?; write_char(writer, COMMA)?;
} }