[ox] Make Result copyTo and moveTo take refs
This commit is contained in:
parent
935099f8d4
commit
d31938ba4f
2
deps/ox/src/ox/model/typestore.hpp
vendored
2
deps/ox/src/ox/model/typestore.hpp
vendored
@ -58,7 +58,7 @@ class TypeStore {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
oxRequireM(dt, loadDescriptor(typeId));
|
||||
for (auto &f : dt->fieldList) {
|
||||
oxReturnError(this->getLoad(f.typeId).moveTo(&f.type));
|
||||
oxReturnError(this->getLoad(f.typeId).moveTo(f.type));
|
||||
}
|
||||
auto &out = m_cache[typeId];
|
||||
out = std::move(dt);
|
||||
|
2
deps/ox/src/ox/oc/read.cpp
vendored
2
deps/ox/src/ox/oc/read.cpp
vendored
@ -265,7 +265,7 @@ Error OrganicClawReader::fieldCString(const char *key, char **val, std::size_t b
|
||||
Error OrganicClawReader::field(const char *key, UUID *val) noexcept {
|
||||
UUIDStr str;
|
||||
oxReturnError(field(key, &str));
|
||||
return UUID::fromString(str).moveTo(val);
|
||||
return UUID::fromString(str).moveTo(*val);
|
||||
}
|
||||
|
||||
Result<std::size_t> OrganicClawReader::arrayLength(const char *key, bool) noexcept {
|
||||
|
2
deps/ox/src/ox/oc/test/tests.cpp
vendored
2
deps/ox/src/ox/oc/test/tests.cpp
vendored
@ -205,7 +205,7 @@ const std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
testIn.Struct.String = "Test String 2";
|
||||
testIn.unionIdx = 1;
|
||||
testIn.Union.Int = 93;
|
||||
oxAssert(ox::writeOC(testIn).moveTo(&dataBuff), "Data generation failed");
|
||||
oxAssert(ox::writeOC(testIn).moveTo(dataBuff), "Data generation failed");
|
||||
ox::TypeStore typeStore;
|
||||
auto type = ox::buildTypeDef(&typeStore, &testIn);
|
||||
oxAssert(type.error, "Descriptor write failed");
|
||||
|
2
deps/ox/src/ox/preloader/preloader.hpp
vendored
2
deps/ox/src/ox/preloader/preloader.hpp
vendored
@ -199,7 +199,7 @@ constexpr ox::Error Preloader<PlatSpec>::field(CRStringView, const ox::BasicStri
|
||||
const auto restore = m_writer.tellp();
|
||||
std::size_t a = 0;
|
||||
if (sz && sz >= SmallStringSize) {
|
||||
oxReturnError(ox::allocate(&m_writer, sz).moveTo(&a));
|
||||
oxReturnError(ox::allocate(&m_writer, sz).moveTo(a));
|
||||
} else {
|
||||
a = restore;
|
||||
}
|
||||
|
30
deps/ox/src/ox/std/error.hpp
vendored
30
deps/ox/src/ox/std/error.hpp
vendored
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user