about summary refs log tree commit diff
path: root/tvix/derivation/src/derivation.rs
diff options
context:
space:
mode:
authorJürgen Hahn <mail.jhahn@gmail.com>2023-01-04T11·26+0100
committerjrhahn <mail.jhahn@gmail.com>2023-01-04T11·38+0000
commitabd539ddb8778a19f32d8ed7e030a28670e1c580 (patch)
tree701752c2cba86a1302a15806c694d0b42fba45aa /tvix/derivation/src/derivation.rs
parent00dab6142ed30a5de93ab0c549916b10fa60036a (diff)
feat(tvix/derivation) Add fmt::Display implementation for Derivation r/5577
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
Diffstat (limited to 'tvix/derivation/src/derivation.rs')
-rw-r--r--tvix/derivation/src/derivation.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/tvix/derivation/src/derivation.rs b/tvix/derivation/src/derivation.rs
index 142fa3c9f309..406d2e0a5787 100644
--- a/tvix/derivation/src/derivation.rs
+++ b/tvix/derivation/src/derivation.rs
@@ -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)
+    }
+}