From 641e722b86568a74a57b9841e4af44f5df2f312a Mon Sep 17 00:00:00 2001 From: mat <26722564+matcool@users.noreply.github.com> Date: Sat, 23 Nov 2024 16:42:10 -0300 Subject: [PATCH] begin simple docs --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8131e93..24aa720 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,21 @@ # Result -A result class for C++ implemented mainly for Geode. \ No newline at end of file +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 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 +```