Skip to content
C++ implementation of Rust's Result
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Build Status

C++ Result

Result for C++ an implementation of Rust's Enum type Result. This C++ implementation tries to be as close to the original thing as possible. Of course, it won't be because of the language difference between the two.


  • and() and or() are called and_() and or_() in this implementation because and and or are keywords in C++.
  • To create an Err Result use the static member from_error().
  • A panic is a std::runtime_error.
  • unwrap(), unwrap_err() and expect() do not display the error value or the okay value when they panic. This is because it might not be possible to convert the type into a string.


The ability to check for equality between a Result and a value was added. However, one problem arose when this feature was added. If the template types are the same (for example Result<int, int> or Result<std::string, std::string>) then a compiler error will be displayed if equality checking is used. This bug will have to be fixed in the near future. Anyone wanting to help with this issue, please work on the template branch. Your help will be appreciated.

Quick Start

This library contains a header and a source file. Just include the header and add the source file to your list of files to build. Result for C++ uses some C++ 17 library features so you will need a compiler that supports C++ 17.

Compile with clang++ -o program main.cpp other_file.cpp -std=c++17

In other_file.cpp:

#include "result.hpp"



Currently, no documentation exist at the moment. The best source of documentation is at the Rust STD Documentation website.

You can’t perform that action at this time.