From 92eccfbd68f80e4a5d87556d43927d6dbaabae26 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 1 Sep 2024 01:37:10 +0200 Subject: [PATCH] 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 --- src/libutil/meson.build | 1 + src/libutil/result.hh | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/libutil/result.hh diff --git a/src/libutil/meson.build b/src/libutil/meson.build index 1ac31c7eb..a3f21de59 100644 --- a/src/libutil/meson.build +++ b/src/libutil/meson.build @@ -105,6 +105,7 @@ libutil_headers = files( 'regex-combinators.hh', 'regex.hh', 'repair-flag.hh', + 'result.hh', 'serialise.hh', 'shlex.hh', 'signals.hh', diff --git a/src/libutil/result.hh b/src/libutil/result.hh new file mode 100644 index 000000000..b01766fe4 --- /dev/null +++ b/src/libutil/result.hh @@ -0,0 +1,24 @@ +#pragma once +/// @file + +#include +#include +#include +#include + +namespace nix { + +template +using Result = boost::outcome_v2::std_result; + +template +using Outcome = boost::outcome_v2::std_outcome; + +namespace result { + +using boost::outcome_v2::success; +using boost::outcome_v2::failure; + +} + +}