diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-07-01 17:07:04 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-07-01 17:07:04 +0100 |
| commit | 2e2d1bd3b6c7776b77c33b94f30ead89367a71e6 (patch) | |
| tree | 54d37ffadf8e677938d9b7a28e4e9b71be1e75c1 /nihil.config/string.cc | |
| parent | 36427c0966faa7aecd586b397ed9b845f18172f5 (diff) | |
| download | nihil-2e2d1bd3b6c7776b77c33b94f30ead89367a71e6.tar.gz nihil-2e2d1bd3b6c7776b77c33b94f30ead89367a71e6.tar.bz2 | |
add nihil.std
Diffstat (limited to 'nihil.config/string.cc')
| -rw-r--r-- | nihil.config/string.cc | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/nihil.config/string.cc b/nihil.config/string.cc deleted file mode 100644 index 0ca4605..0000000 --- a/nihil.config/string.cc +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This source code is released into the public domain. - */ - -module; - -#include <coroutine> -#include <expected> -#include <format> -#include <string> - -module nihil.config; - -import nihil.error; -import nihil.monad; -import nihil.ucl; - -namespace nihil::config { - -string::string( - std::string &storage, - std::string_view name, - std::string_view description) noexcept - : option(name, description) - , m_storage(storage) -{ -} - -string::~string() = default; - -auto string::get_string() const -> std::string -{ - return m_storage; -} - -auto string::set_string(std::string_view new_value) - -> std::expected<void, error> -{ - m_storage = new_value; - return {}; -} - -auto string::get_ucl() const -> std::expected<ucl::object, error> -{ - return ucl::string(m_storage); -} - -auto string::set_ucl(ucl::object const &uclobj) -> std::expected<void, error> -{ - auto obj = co_await object_cast<ucl::string>(uclobj) - .transform_error([&] (ucl::type_mismatch const &m) { - return error(std::format( - "'{}': expected string, not {}", - name(), str(m.actual_type()))); - }); - - m_storage = obj.value(); - is_default(false); - co_return {}; -} - -} // namespace nihil::config |
