Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
result.hh
Go to the documentation of this file.
1#pragma once
3
4#include "nix/util/error.hh"
5
6#include <boost/outcome/result.hpp>
7
8#include <functional>
9#include <type_traits>
10
11namespace nix {
12
13namespace outcome = BOOST_OUTCOME_V2_NAMESPACE;
14
23template<typename T, typename E>
24using Result = outcome::unchecked<T, E>;
25
32template<typename T, typename E, typename F>
33T valueOr(Result<T, E> && result, F && f)
34{
35 if (result)
36 return std::move(result).value();
37 if constexpr (std::is_void_v<std::invoke_result_t<F, E>>) {
38 std::invoke(std::forward<F>(f), std::move(result).error());
39 unreachable();
40 } else
41 return std::invoke(std::forward<F>(f), std::move(result).error());
42}
43
44} // namespace nix
45
54#define NIX_THROW_NATIVE_SYS_ERROR_HANDLER(...) [&](auto err__) { throw ::nix::NativeSysError(err__, __VA_ARGS__); }
This file defines two main structs/classes used in nix error handling.
T valueOr(Result< T, E > &&result, F &&f)
Definition result.hh:33
outcome::unchecked< T, E > Result
Definition result.hh:24