feat(tvix/derivation) Add fmt::Display implementation for Derivation

This adds the implementation of fmt::Display for Derivation so that we can
easily store the formatted content as a string. Internally, we use the
serialization function to generate the string.

Change-Id: I6caca0d6c1bea3ca44b6c535c5b1d5d66d8413b7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7741
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
This commit is contained in:
Jürgen Hahn 2023-01-04 12:26:37 +01:00 committed by jrhahn
parent 00dab6142e
commit abd539ddb8
3 changed files with 42 additions and 22 deletions

View file

@ -15,20 +15,26 @@ pub struct Derivation {
}
impl Derivation {
pub fn serialize(self: Self, writer: &mut impl Write) -> Result<(), fmt::Error> {
pub fn serialize(&self, writer: &mut impl Write) -> Result<(), fmt::Error> {
writer.write_str(write::DERIVATION_PREFIX)?;
writer.write_char(write::PAREN_OPEN)?;
write::write_outputs(writer, self.outputs)?;
write::write_input_derivations(writer, self.input_derivations)?;
write::write_input_sources(writer, self.input_sources)?;
write::write_outputs(writer, &self.outputs)?;
write::write_input_derivations(writer, &self.input_derivations)?;
write::write_input_sources(writer, &self.input_sources)?;
write::write_platfrom(writer, &self.platform)?;
write::write_builder(writer, &self.builder)?;
write::write_arguments(writer, self.arguments)?;
write::write_enviroment(writer, self.environment)?;
write::write_arguments(writer, &self.arguments)?;
write::write_enviroment(writer, &self.environment)?;
writer.write_char(write::PAREN_CLOSE)?;
Ok(())
}
}
impl fmt::Display for Derivation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.serialize(f)
}
}