aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/print.hh
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-08 04:49:08 +0100
committereldritch horrors <pennae@lix.systems>2024-03-09 00:05:41 -0700
commit87e6ac5eb706593d15d29b070eac5f05e305a787 (patch)
tree79062f2ab0e8a298de9b68419fa4094994e26e22 /src/libexpr/print.hh
parent896e525681bbf696c330af4e51c5e161d3818350 (diff)
Merge pull request #9753 from 9999years/print-value-on-type-error
Print the value in `value is X while a Y is expected` error (cherry picked from commit 5f72a97092da6af28a7d2b2a50d74e9d34fae7e1) Change-Id: Idb4bc903ae59a0f5b6fb3b1da4d47970fe0a6efe
Diffstat (limited to 'src/libexpr/print.hh')
-rw-r--r--src/libexpr/print.hh21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/libexpr/print.hh b/src/libexpr/print.hh
index 40207d777..a8300264a 100644
--- a/src/libexpr/print.hh
+++ b/src/libexpr/print.hh
@@ -9,11 +9,13 @@
#include <iostream>
-#include "eval.hh"
#include "print-options.hh"
namespace nix {
+class EvalState;
+struct Value;
+
/**
* Print a string as a Nix string literal.
*
@@ -59,4 +61,21 @@ std::ostream & printIdentifier(std::ostream & o, std::string_view s);
void printValue(EvalState & state, std::ostream & str, Value & v, PrintOptions options = PrintOptions {});
+/**
+ * A partially-applied form of `printValue` which can be formatted using `<<`
+ * without allocating an intermediate string.
+ */
+class ValuePrinter {
+ friend std::ostream & operator << (std::ostream & output, const ValuePrinter & printer);
+private:
+ EvalState & state;
+ Value & value;
+ PrintOptions options;
+
+public:
+ ValuePrinter(EvalState & state, Value & value, PrintOptions options = PrintOptions {})
+ : state(state), value(value), options(options) { }
+};
+
+std::ostream & operator<<(std::ostream & output, const ValuePrinter & printer);
}