Skip to content

Commit

Permalink
Bump mitama-cpp-result up to 11.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui committed Jan 20, 2025
1 parent 69a737e commit 713c0bf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cabin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ version = "0.12.0-dev"

[dependencies]
toml11 = {git = "https://github.com/ToruNiina/toml11.git", tag = "v4.2.0"}
mitama-cpp-result = {git = "https://github.com/loliGothicK/mitama-cpp-result.git", tag = "v10.0.4"}
mitama-cpp-result = {git = "https://github.com/loliGothicK/mitama-cpp-result.git", tag = "v11.0.0"}
fmt = {version = ">=9 && <12", system = true}
libcurl = {version = ">=7.79.1 && <9", system = true}
libgit2 = {version = ">=1.7 && <1.10", system = true}
Expand Down
2 changes: 1 addition & 1 deletion src/Algos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ getCmdOutput(const Command& cmd, const std::size_t retry) noexcept {
waitTime *= 2;
}

return Result<std::string>(Err(Anyhow(
return Result<std::string>(Err(anyhow::anyhow(
"Command `{}` failed with exit code {}",
cmd.toString(), exitCode
)))
Expand Down
31 changes: 5 additions & 26 deletions src/Rustify/Result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@
#include <fmt/core.h>
#include <mitama/anyhow/anyhow.hpp>
#include <mitama/result/result.hpp>
#include <mitama/thiserror/thiserror.hpp>
#include <string>
#include <type_traits>
#include <utility>

namespace anyhow = mitama::anyhow;
namespace thiserror = mitama::thiserror;

// NOLINTBEGIN(readability-identifier-naming,cppcoreguidelines-macro-usage)

#define Try(...) MITAMA_TRY(__VA_ARGS__)
#define Bail(...) return Err(Anyhow(__VA_ARGS__))
#define Ensure(cond, ...) \
do { \
if (!(cond)) { \
Bail(__VA_ARGS__); \
} \
} while (false)
#define Bail(...) MITAMA_BAIL(__VA_ARGS__)
#define Ensure(...) MITAMA_ENSURE(__VA_ARGS__)

struct UseAnyhow {};

Expand All @@ -37,6 +30,7 @@ Ok(Args&&... args) -> decltype(mitama::success(std::forward<Args>(args)...)) {
}

template <typename E = void, typename... Args>
requires std::is_void_v<E> || std::is_base_of_v<anyhow::error, E>
inline auto
Err(Args&&... args) {
if constexpr (std::is_void_v<E>) {
Expand All @@ -46,23 +40,8 @@ Err(Args&&... args) {
}
}

template <thiserror::fixed_string S, typename... T>
using Error = thiserror::error<S, T...>;

template <typename... T>
requires(fmt::is_formattable<T>::value && ...)
inline auto
Anyhow(fmt::format_string<T...> f, T&&... args) {
return anyhow::anyhow(fmt::format(f, std::forward<T>(args)...));
}
template <typename T>
inline auto
Anyhow(T&& arg) {
return anyhow::anyhow(std::forward<T>(arg));
}

inline constexpr auto to_anyhow = [](std::string e) {
return anyhow::anyhow(std::move(e));
inline constexpr auto to_anyhow = [](auto... xs) {
return anyhow::anyhow(std::forward<decltype(xs)>(xs)...);
};

#if __has_include(<toml.hpp>)
Expand Down

0 comments on commit 713c0bf

Please sign in to comment.