[ox] Make Result copyTo and moveTo take refs

This commit is contained in:
2023-12-14 22:26:17 -06:00
parent 935099f8d4
commit d31938ba4f
5 changed files with 27 additions and 11 deletions

View File

@ -165,23 +165,39 @@ struct [[nodiscard]] Result {
return error == 0;
}
constexpr Error copyTo(type *val) const noexcept {
constexpr Error copyTo(type &val) const & noexcept {
if (!error) [[likely]] {
*val = value;
}
return error;
}
constexpr Error copyTo(type &val) const && noexcept {
if (!error) [[likely]] {
*val = value;
}
return error;
}
constexpr Error copyTo(type &val) & noexcept {
*val = value;
return error;
}
constexpr Error copyTo(type *val) noexcept {
*val = value;
return error;
}
constexpr Error moveTo(type *val) noexcept {
constexpr Error copyTo(type &val) && noexcept {
if (!error) [[likely]] {
*val = std::move(value);
}
return error;
}
constexpr Error moveTo(type &val) noexcept {
if (!error) [[likely]] {
val = std::move(value);
}
return error;
}
constexpr T &unwrap() & noexcept {
if (error) {
oxPanic(error, "Failed unwrap");