We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d1251ac commit 641e722Copy full SHA for 641e722
README.md
@@ -1,3 +1,21 @@
1
# Result
2
3
-A result class for C++ implemented mainly for Geode.
+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