mirror of
https://github.com/NixOS/nix
synced 2025-07-05 16:31:47 +02:00
Introduce DerivationOptions
This is a first step towards PR #10760, and the issues it addresses. See the Doxygen for details. Thanks to these changes, we are able to drastically restrict how the rest of the code-base uses `ParseDerivation`. Co-Authored-By: HaeNoe <git@haenoe.party>
This commit is contained in:
parent
f0dbfada38
commit
917b8b2f77
14 changed files with 664 additions and 279 deletions
|
@ -3,6 +3,7 @@
|
|||
#include "types.hh"
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
@ -38,6 +39,15 @@ std::optional<nlohmann::json> optionalValueAt(const nlohmann::json::object_t & m
|
|||
return std::optional { map.at(key) };
|
||||
}
|
||||
|
||||
std::optional<nlohmann::json> nullableValueAt(const nlohmann::json::object_t & map, const std::string & key)
|
||||
{
|
||||
auto value = valueAt(map, key);
|
||||
|
||||
if (value.is_null())
|
||||
return std::nullopt;
|
||||
|
||||
return std::optional { std::move(value) };
|
||||
}
|
||||
|
||||
const nlohmann::json * getNullable(const nlohmann::json & value)
|
||||
{
|
||||
|
|
|
@ -25,6 +25,7 @@ const nlohmann::json & valueAt(
|
|||
const std::string & key);
|
||||
|
||||
std::optional<nlohmann::json> optionalValueAt(const nlohmann::json::object_t & value, const std::string & key);
|
||||
std::optional<nlohmann::json> nullableValueAt(const nlohmann::json::object_t & value, const std::string & key);
|
||||
|
||||
/**
|
||||
* Downcast the json object, failing with a nice error if the conversion fails.
|
||||
|
@ -69,6 +70,9 @@ struct json_avoids_null<std::vector<T>> : std::true_type {};
|
|||
template<typename T>
|
||||
struct json_avoids_null<std::list<T>> : std::true_type {};
|
||||
|
||||
template<typename T>
|
||||
struct json_avoids_null<std::set<T>> : std::true_type {};
|
||||
|
||||
template<typename K, typename V>
|
||||
struct json_avoids_null<std::map<K, V>> : std::true_type {};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue