Skip to content

Commit

Permalink
begin simple docs
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool authored Nov 23, 2024
1 parent d1251ac commit 641e722
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Result

A result class for C++ implemented mainly for Geode.
A result class for C++ implemented mainly for Geode.

The purpose of the class is wrapping the return value of a function which may fail, thus passing the error as part of the return type.

The design of this library is heavily inspired by [rust's Result type](https://doc.rust-lang.org/std/result/)

## Example

```cpp
Result<int> integerDivision(int a, int b) {
if (b == 0)
return Err("Division by zero");
return Ok(a / b);
}

int value = integerDivision(3, 2).unwrap(); // 1
value = integerDivision(3, 0).unwrap(); // Throws a runtime error
value = integerDivision(3, 0).unwrapOr(0); // 0
```

0 comments on commit 641e722

Please sign in to comment.