Added support for exception-free TOML; resolves #436 (#447)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2025-06-09 21:45:09 +02:00
committed by GitHub
parent a0fe3975e8
commit 3789268ac3
+15 -3
View File
@@ -29,9 +29,21 @@ auto read(InputVarType _var) {
/// Reads a TOML string.
template <class T, class... Ps>
Result<internal::wrap_in_rfl_array_t<T>> read(
const std::string_view _toml_str) {
auto table = ::toml::parse(_toml_str);
return read<T, Ps...>(&table);
const std::string_view _toml_str) noexcept {
#if TOML_EXCEPTIONS
try {
auto table = ::toml::parse(_toml_str);
return read<T, Ps...>(&table);
} catch (const std::exception& e) {
return error(e.what());
}
#else
auto result = ::toml::parse(_toml_str);
if (!result) {
return error(std::string(result.error().description()));
}
return read<T, Ps...>(&result.table());
#endif
}
/// Parses an object from a stringstream.