Skip to content

Commit 3789268

Browse files
Added support for exception-free TOML; resolves #436 (#447)
1 parent a0fe397 commit 3789268

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

include/rfl/toml/read.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,21 @@ auto read(InputVarType _var) {
2929
/// Reads a TOML string.
3030
template <class T, class... Ps>
3131
Result<internal::wrap_in_rfl_array_t<T>> read(
32-
const std::string_view _toml_str) {
33-
auto table = ::toml::parse(_toml_str);
34-
return read<T, Ps...>(&table);
32+
const std::string_view _toml_str) noexcept {
33+
#if TOML_EXCEPTIONS
34+
try {
35+
auto table = ::toml::parse(_toml_str);
36+
return read<T, Ps...>(&table);
37+
} catch (const std::exception& e) {
38+
return error(e.what());
39+
}
40+
#else
41+
auto result = ::toml::parse(_toml_str);
42+
if (!result) {
43+
return error(std::string(result.error().description()));
44+
}
45+
return read<T, Ps...>(&result.table());
46+
#endif
3547
}
3648

3749
/// Parses an object from a stringstream.

0 commit comments

Comments
 (0)