Skip to content

Commit

Permalink
docs: Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmah309 committed Dec 12, 2023
1 parent c385bf2 commit 098f1c2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions lib/src/panic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ Rust vs Dart Error handling terminology:
| Exception | Error |
| Error | Panic |

Thus, here `Error` implements Dart core `Exception` (Not to be confused with the
Dart core `Error` type) and `Panic` implements Dart core `Error`.
```dart
Result x = Err(1);
if (x.isErr()) {
return x.unwrap(); // this will throw a Panic (should be "unwrapErr()")
}
```

Rust core was designed with safety in mind. The only time anyhow will ever throw is if you `unwrap` incorrectly (as
rust_core was designed with safety in mind. The only time rust_core will ever throw is if you `unwrap` incorrectly (as
above), in
this case a `Panic`'s can be thrown. See
[How to Never Unwrap Incorrectly](https://github.com/mcmah309/rust_core#how-to-never-unwrap-incorrectly) section to
avoid ever using `unwrap`.
this case a `Panic`'s can be thrown. But the good news is you should never need to use these
methods. See [How to Never Unwrap Incorrectly]
section to
avoid ever using `unwrap`.

[How to Never Unwrap Incorrectly]:https://github.com/mcmah309/rust_core/tree/master/lib/src/result#how-to-never-unwrap-incorrectly
4 changes: 2 additions & 2 deletions lib/src/result/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ String makeFood(int orderNumber) {
String makeHamburger() {
// Who catches this??
// How do we know we won't forget to catch this??
// What is the context around this error??
throw "Hmm something went wrong making the hamburger.";
}
```
Expand Down Expand Up @@ -94,10 +93,11 @@ Result<String, String> makeFood(int orderNumber) {
}
Result<String,String> makeHamburger() {
// What is the context around this error??
return Err("Hmm something went wrong making the hamburger.");
}
```
Now with the `Result` type there are no more undefined
behaviours due to control flow!
### Chaining
Effects on a `Result` can be chained in a safe way without
needing a bunch of `if` statements, similar to `Option`.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/typedefs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Result<void, void> y = Err(1); // valid
int z = x.unwrap(); // not valid
```

Since stricter types are preferred and `Err` cannot be null, use `()` or `Unit`:
Since stricter types are preferred and `Err` cannot be null, use `()` aka `Unit`:

```dart
Unit == ().runtimeType; // true
Expand Down

0 comments on commit 098f1c2

Please sign in to comment.