Result: Construct a Result from an Option using from_option()

This commit is contained in:
apio 2023-01-11 23:02:15 +01:00
parent 79a5b98d65
commit 0e1e15e85a
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -127,6 +127,13 @@ template <typename T> class Result
return m_value.unchecked_release_value({});
}
static Result<T> from_option(Option<T>&& option, int error)
{
if (option.has_value()) { return option.unchecked_release_value({}); }
else
return Error { error };
}
private:
Option<T> m_value;
int m_error;