From 0e1e15e85af60ed654cad1a3e0cb4167b4a3ade0 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 11 Jan 2023 23:02:15 +0100 Subject: [PATCH] Result: Construct a Result from an Option using from_option() --- luna/include/luna/Result.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/luna/include/luna/Result.h b/luna/include/luna/Result.h index 9b1114d2..b5f128e4 100644 --- a/luna/include/luna/Result.h +++ b/luna/include/luna/Result.h @@ -127,6 +127,13 @@ template class Result return m_value.unchecked_release_value({}); } + static Result from_option(Option&& option, int error) + { + if (option.has_value()) { return option.unchecked_release_value({}); } + else + return Error { error }; + } + private: Option m_value; int m_error;