Skip to content

Commit d83d62b

Browse files
authored
Update migrate-v4.md
1 parent 770e02c commit d83d62b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tutorials/migrate-v4.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
* Snake case methods renamed to camel case
99
* Universal `GEODE_UNWRAP(res)` and `GEODE_UNWRAP_INTO(value, res)` macros
1010
* These macros were already previously available, but this is just a reminder that they can help a lot when dealing with results.
11+
```cpp
12+
Result<std::string> addValues(matjson::Value json) {
13+
// Value::asInt() returns a Result<int>
14+
GEODE_UNWRAP_INTO(int a, json["a"].asInt());
15+
GEODE_UNWRAP_INTO(int b, json["b"].asInt());
16+
// must wrap return value with Ok
17+
return Ok(fmt::format("sum is {}", a + b));
18+
}
19+
```
1120
* If you only ever expect to build your code with **clang**, you can use the `GEODE_UNWRAP` macro like so, for convenience:
1221
```cpp
1322
Result<int> getInt();

0 commit comments

Comments
 (0)