diff options
| -rw-r--r-- | kernel/kernel/filesystem/ext2/inode.cpp | 2 | ||||
| -rw-r--r-- | libs/kstd/kstd/result.hpp | 17 |
2 files changed, 15 insertions, 4 deletions
diff --git a/kernel/kernel/filesystem/ext2/inode.cpp b/kernel/kernel/filesystem/ext2/inode.cpp index 5f161e82..8da80191 100644 --- a/kernel/kernel/filesystem/ext2/inode.cpp +++ b/kernel/kernel/filesystem/ext2/inode.cpp @@ -122,7 +122,7 @@ namespace kernel::filesystem::ext2 // TODO BA-FS26 if blocknumber == 0 --> handle sparse file if (!block_number) { - kstd::failure(block_number.error()); + return kstd::failure(block_number.error()); } auto const bytes_to_write = diff --git a/libs/kstd/kstd/result.hpp b/libs/kstd/kstd/result.hpp index 7b027a8d..ae15f079 100644 --- a/libs/kstd/kstd/result.hpp +++ b/libs/kstd/kstd/result.hpp @@ -10,22 +10,33 @@ namespace kstd { + //! A type alias to hold results of functions that may fail. + //! + //! This is a convenience alias mapping to std::expected. It is intended to reduce the duplication of the unexpected + //! type across the codebase. template<typename SuccessType> using result = std::expected<SuccessType, error_code>; + //! Create a new success case. + //! + //! @param value The value to to stash in the success result. template<typename SuccessType> requires(!std::is_void_v<SuccessType>) - constexpr auto inline success(SuccessType && value) -> result<std::remove_cvref_t<SuccessType>> + [[nodiscard]] constexpr auto inline success(SuccessType && value) -> result<std::remove_cvref_t<SuccessType>> { return result<std::remove_cvref_t<SuccessType>>{std::in_place, std::forward<SuccessType>(value)}; } - constexpr auto inline success() -> result<void> + //! Create an empty success case. + [[nodiscard]] constexpr auto inline success() -> result<void> { return result<void>{std::in_place}; } - constexpr auto inline failure(error_code error) -> std::unexpected<error_code> + //! Create a failure case. + //! + //! @param error The error that occurred. + [[nodiscard]] constexpr auto inline failure(error_code error) -> std::unexpected<error_code> { return std::unexpected(error); } |
