1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-15 23:12:44 +01:00

Allow for standard nlohmann JSON serializers to take separate XP features

I realized that we can actually do this thing, even though it is not
what nlohmann expects at all, because the extra parameter has a default
argument so nlohmann doesn't need to care. Sneaky!
This commit is contained in:
John Ericson 2025-10-16 15:49:47 -04:00
parent d87a06af7a
commit 1c02dd5b9c
5 changed files with 35 additions and 32 deletions

View file

@ -3,6 +3,8 @@
#include <nlohmann/json_fwd.hpp>
#include "nix/util/experimental-features.hh"
// Following https://github.com/nlohmann/json#how-can-i-use-get-for-non-default-constructiblenon-copyable-types
#define JSON_IMPL(TYPE) \
namespace nlohmann { \
@ -14,3 +16,15 @@
static void to_json(json & json, const TYPE & t); \
}; \
}
#define JSON_IMPL_WITH_XP_FEATURES(TYPE) \
namespace nlohmann { \
using namespace nix; \
template<> \
struct adl_serializer<TYPE> \
{ \
static TYPE \
from_json(const json & json, const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings); \
static void to_json(json & json, const TYPE & t); \
}; \
}