libutil: add a result type using boost outcome

we're using boost::outcome rather than leaf or stl types because stl
types are not available everywhere and leaf does not provide its own
storage for error values, relying on thread-locals and the stack. if
we want to use promises we won't have a stack and would have to wrap
everything into leaf-specific allocating wrappers, so outcome it is.

Change-Id: I35111a1f9ed517e7f12a839e2162b1ba6a993f8f
This commit is contained in:
eldritch horrors 2024-09-01 01:37:10 +02:00
parent 991d8ce275
commit 92eccfbd68
2 changed files with 25 additions and 0 deletions

View file

@ -105,6 +105,7 @@ libutil_headers = files(
'regex-combinators.hh', 'regex-combinators.hh',
'regex.hh', 'regex.hh',
'repair-flag.hh', 'repair-flag.hh',
'result.hh',
'serialise.hh', 'serialise.hh',
'shlex.hh', 'shlex.hh',
'signals.hh', 'signals.hh',

24
src/libutil/result.hh Normal file
View file

@ -0,0 +1,24 @@
#pragma once
/// @file
#include <boost/outcome/std_outcome.hpp>
#include <boost/outcome/std_result.hpp>
#include <boost/outcome/success_failure.hpp>
#include <exception>
namespace nix {
template<typename T, typename E = std::exception_ptr>
using Result = boost::outcome_v2::std_result<T, E>;
template<typename T, typename D, typename E = std::exception_ptr>
using Outcome = boost::outcome_v2::std_outcome<T, D, E>;
namespace result {
using boost::outcome_v2::success;
using boost::outcome_v2::failure;
}
}