refactor(tvix/derivation): refactor the derivation serialization

This refactors the code to serialize a derivation. The original code
has beed moved to seperate crates for better code structure.

Change-Id: I3b1a6b134428fcbc9930c330bced8ec3610cfb4c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7733
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
Jürgen Hahn 2023-01-02 21:00:59 +01:00 committed by jrhahn
parent e6862413ca
commit 31973890a9
6 changed files with 248 additions and 215 deletions

View file

@ -0,0 +1,17 @@
const STRING_ESCAPER: [(char, &str); 5] = [
('\\', "\\\\"),
('\n', "\\n"),
('\r', "\\r"),
('\t', "\\t"),
('\"', "\\\""),
];
pub fn escape_string(s: &str) -> String {
let mut s_replaced = s.to_string();
for escape_sequence in STRING_ESCAPER {
s_replaced = s_replaced.replace(escape_sequence.0, escape_sequence.1);
}
format!("\"{}\"", s_replaced)
}