From 098f1c26fa0bffc072718b5d9fbda71631eab058 Mon Sep 17 00:00:00 2001 From: mcmah309 Date: Tue, 12 Dec 2023 08:44:40 -0500 Subject: [PATCH] docs: Update --- lib/src/panic/README.md | 13 +++++++------ lib/src/result/README.md | 4 ++-- lib/src/typedefs/README.md | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/src/panic/README.md b/lib/src/panic/README.md index 50c0d3a..7811025 100644 --- a/lib/src/panic/README.md +++ b/lib/src/panic/README.md @@ -7,8 +7,6 @@ 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()) { @@ -16,8 +14,11 @@ if (x.isErr()) { } ``` -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`. \ No newline at end of file +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 \ No newline at end of file diff --git a/lib/src/result/README.md b/lib/src/result/README.md index e1ff86d..b9cf697 100644 --- a/lib/src/result/README.md +++ b/lib/src/result/README.md @@ -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."; } ``` @@ -94,10 +93,11 @@ Result makeFood(int orderNumber) { } Result 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`. diff --git a/lib/src/typedefs/README.md b/lib/src/typedefs/README.md index 4a39154..9595bde 100644 --- a/lib/src/typedefs/README.md +++ b/lib/src/typedefs/README.md @@ -7,7 +7,7 @@ Result 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