mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-31 00:05:13 +02:00
Merge bitcoin/bitcoin#25594: refactor: Return BResult from restoreWallet
fa475e9c79refactor: Return BResult from restoreWallet (MacroFake)fa8de09edcPrepare BResult for non-copyable types (MacroFake) Pull request description: This avoids the `error` in-out param (and if `warnings` is added to `BResult`, it will avoid passing that in-out param as well). Also, as it is needed for this change, prepare `BResult` for non-copyable types. ACKs for top commit: w0xlt: reACKfa475e9c79ryanofsky: Code review ACKfa475e9c79. Changes since last review were replacing auto with explicit type and splitting commits Tree-SHA512: 46350883572f13721ddd198f5dfb88d2fa58ebcbda416f74da3563ea15c920fb1e6ff30558526a4ac91c36c21e6afe27751a4e51b7b8bcbcbe805209f4e9014b
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#define BITCOIN_UTIL_RESULT_H
|
||||
|
||||
#include <util/translation.h>
|
||||
|
||||
#include <variant>
|
||||
|
||||
/*
|
||||
@@ -18,9 +19,9 @@ private:
|
||||
std::variant<bilingual_str, T> m_variant;
|
||||
|
||||
public:
|
||||
BResult() : m_variant(Untranslated("")) {}
|
||||
BResult(const T& _obj) : m_variant(_obj) {}
|
||||
BResult(const bilingual_str& error) : m_variant(error) {}
|
||||
BResult() : m_variant{Untranslated("")} {}
|
||||
BResult(T obj) : m_variant{std::move(obj)} {}
|
||||
BResult(bilingual_str error) : m_variant{std::move(error)} {}
|
||||
|
||||
/* Whether the function succeeded or not */
|
||||
bool HasRes() const { return std::holds_alternative<T>(m_variant); }
|
||||
@@ -30,6 +31,11 @@ public:
|
||||
assert(HasRes());
|
||||
return std::get<T>(m_variant);
|
||||
}
|
||||
T ReleaseObj()
|
||||
{
|
||||
assert(HasRes());
|
||||
return std::move(std::get<T>(m_variant));
|
||||
}
|
||||
|
||||
/* In case of failure, the error cause */
|
||||
const bilingual_str& GetError() const {
|
||||
|
||||
Reference in New Issue
Block a user