aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.config/string.ccm
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-26 20:47:45 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-26 20:47:45 +0100
commit90aa957ca9b7c217af7569009d1675e0f3ff8e9b (patch)
treee6a61ca2b6928e6414372b9b1484ce80fa2fb0b3 /nihil.config/string.ccm
parent1db86c401df11423c945634d8b2a483e97afa878 (diff)
downloadnihil-90aa957ca9b7c217af7569009d1675e0f3ff8e9b.tar.gz
nihil-90aa957ca9b7c217af7569009d1675e0f3ff8e9b.tar.bz2
ucl, config: use monadic error handling more
Diffstat (limited to 'nihil.config/string.ccm')
-rw-r--r--nihil.config/string.ccm34
1 files changed, 28 insertions, 6 deletions
diff --git a/nihil.config/string.ccm b/nihil.config/string.ccm
index ae5efb9..b6a7e05 100644
--- a/nihil.config/string.ccm
+++ b/nihil.config/string.ccm
@@ -4,16 +4,21 @@
module;
+#include <expected>
#include <format>
#include <string>
export module nihil.config:string;
+import nihil;
import nihil.ucl;
import :option;
namespace nihil::config {
+/*
+ * A string option. The backing type is std::string.
+ */
export struct string final : option
{
string(std::string &storage,
@@ -22,14 +27,31 @@ export struct string final : option
~string();
- auto get_string() const -> std::string override;
- auto set_string(std::string_view new_value) -> void override;
-
- auto to_ucl() const -> ucl::object override;
- auto from_ucl(ucl::object const &uclobj) -> void override;
+ /*
+ * Get this option as a string; simply returns the storage.
+ */
+ [[nodiscard]] auto get_string() const -> std::string override;
+
+ /*
+ * Set this option to a string value; assigns to the storage.
+ */
+ [[nodiscard]] auto set_string(std::string_view new_value)
+ -> std::expected<void, error> override;
+
+ /*
+ * Convert this option to a UCL object.
+ */
+ [[nodiscard]] auto get_ucl() const
+ -> std::expected<ucl::object, error> override;
+
+ /*
+ * Set this option from a UCL object.
+ */
+ [[nodiscard]] auto set_ucl(ucl::object const &uclobj)
+ -> std::expected<void, error> override;
private:
- std::string &_storage;
+ std::string &m_storage;
};
} // namespace nihil::config