aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-07-13 12:18:08 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-07-13 12:18:08 +0200
commit34ffa4de405d053ef4b53d58e1437f2e82d152b1 (patch)
tree7c0be634f0a8ecaba479f68ecb77ba4f7c74e9b3 /libs
parent48b95e0b46e32f35ea6f16f41ab99286856292bf (diff)
downloadkernel-34ffa4de405d053ef4b53d58e1437f2e82d152b1.tar.xz
kernel-34ffa4de405d053ef4b53d58e1437f2e82d152b1.zip
kstd: make error_code formattable
Diffstat (limited to 'libs')
-rw-r--r--libs/kstd/kstd/format.hpp1
-rw-r--r--libs/kstd/kstd/system_error.hpp25
2 files changed, 26 insertions, 0 deletions
diff --git a/libs/kstd/kstd/format.hpp b/libs/kstd/kstd/format.hpp
index 5ed798db..5d7f4ae6 100644
--- a/libs/kstd/kstd/format.hpp
+++ b/libs/kstd/kstd/format.hpp
@@ -5,6 +5,7 @@
#include <kstd/bits/format/arg.hpp>
#include <kstd/bits/format/args.hpp>
#include <kstd/bits/format/context.hpp>
+#include <kstd/bits/format/error.hpp>
#include <kstd/bits/format/formatter.hpp>
#include <kstd/bits/format/formatter/bool.hpp>
#include <kstd/bits/format/formatter/byte.hpp>
diff --git a/libs/kstd/kstd/system_error.hpp b/libs/kstd/kstd/system_error.hpp
index f971703b..08725609 100644
--- a/libs/kstd/kstd/system_error.hpp
+++ b/libs/kstd/kstd/system_error.hpp
@@ -1,6 +1,8 @@
#ifndef KSTD_SYSTEM_ERROR_HPP
#define KSTD_SYSTEM_ERROR_HPP
+#include <kstd/format.hpp>
+
#include <compare>
#include <cstdint>
#include <functional>
@@ -472,6 +474,29 @@ namespace kstd
return {static_cast<int>(value), generic_category()};
}
+ template<>
+ struct formatter<error_code>
+ {
+ constexpr auto parse(format_parse_context & context) -> format_parse_context::iterator
+ {
+ auto it = context.begin();
+ if (it != context.end() && *it != '}')
+ {
+ bits::format::error("Invalid specifier for string_view.");
+ }
+ return it;
+ }
+
+ auto format(error_code const & error, format_context & context) const -> void
+ {
+ context.push(error.category().name());
+ context.push(':');
+ formatter<int>{}.format(error.value(), context);
+ context.push(':');
+ context.push(error.message());
+ }
+ };
+
} // namespace kstd
#endif