Skip to content

Commit 641e722

Browse files
authored
begin simple docs
1 parent d1251ac commit 641e722

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
# Result
22

3-
A result class for C++ implemented mainly for Geode.
3+
A result class for C++ implemented mainly for Geode.
4+
5+
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.
6+
7+
The design of this library is heavily inspired by [rust's Result type](https://doc.rust-lang.org/std/result/)
8+
9+
## Example
10+
11+
```cpp
12+
Result<int> integerDivision(int a, int b) {
13+
if (b == 0)
14+
return Err("Division by zero");
15+
return Ok(a / b);
16+
}
17+
18+
int value = integerDivision(3, 2).unwrap(); // 1
19+
value = integerDivision(3, 0).unwrap(); // Throws a runtime error
20+
value = integerDivision(3, 0).unwrapOr(0); // 0
21+
```

0 commit comments

Comments
 (0)