aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/experimental-features.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2022-05-12 19:13:33 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2022-05-12 19:13:33 +0000
commitb18720ee175d6c019be964955efc1633be1c434d (patch)
treeda1daaed8a0c3c45829ba9285f328d31e09476b8 /src/libutil/experimental-features.cc
parent6b61d7722d0b24bc4b5e020a71ada442c19f495d (diff)
parentd354fc30b9768ea3dc737a88b57bf5e26d98135b (diff)
Merge remote-tracking branch 'upstream/master' into indexed-store-path-outputs
Diffstat (limited to 'src/libutil/experimental-features.cc')
-rw-r--r--src/libutil/experimental-features.cc20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/libutil/experimental-features.cc b/src/libutil/experimental-features.cc
index c1e574c0d..a7782237c 100644
--- a/src/libutil/experimental-features.cc
+++ b/src/libutil/experimental-features.cc
@@ -36,7 +36,9 @@ const std::optional<ExperimentalFeature> parseExperimentalFeature(const std::str
std::string_view showExperimentalFeature(const ExperimentalFeature feature)
{
- return stringifiedXpFeatures.at(feature);
+ const auto ret = get(stringifiedXpFeatures, feature);
+ assert(ret);
+ return *ret;
}
std::set<ExperimentalFeature> parseFeatures(const std::set<std::string> & rawFeatures)
@@ -59,4 +61,20 @@ std::ostream & operator <<(std::ostream & str, const ExperimentalFeature & featu
return str << showExperimentalFeature(feature);
}
+void to_json(nlohmann::json & j, const ExperimentalFeature & feature)
+{
+ j = showExperimentalFeature(feature);
+}
+
+void from_json(const nlohmann::json & j, ExperimentalFeature & feature)
+{
+ const std::string input = j;
+ const auto parsed = parseExperimentalFeature(input);
+
+ if (parsed.has_value())
+ feature = *parsed;
+ else
+ throw Error("Unknown experimental feature '%s' in JSON input", input);
+}
+
}