Skip to content

Commit

Permalink
doc: Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmah309 committed Dec 7, 2024
1 parent a3f49c7 commit 13e3af4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

Types include [Result](https://mcmah309.github.io/rust/libs/result/result.html), [Option](https://mcmah309.github.io/rust/libs/option/option.html), [Cell](https://mcmah309.github.io/rust/libs/cell/cell.html), [Slice](https://mcmah309.github.io/rust/libs/slice/slice.html), [Array](https://mcmah309.github.io/rust/libs/array/array.html), [Iterator](https://mcmah309.github.io/rust/libs/iter/iter.html), [Channels](https://mcmah309.github.io/rust/libs/sync/channels.html), [Mutex](https://mcmah309.github.io/rust/libs/sync/mutex.html), [Path](https://mcmah309.github.io/rust/libs/path/path.html) and more.

See the [Book 📖](https://mcmah309.github.io/rust) for more!
See the [Documentation Book 📖](https://mcmah309.github.io/rust) for more!

## Example
## Rust Language vs rust Package Example
> Goal: Get the index of every "!" in a string not followed by a "?"
**Rust:**
**[Rust](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=6010cc86519e58e4592247403830cde7):**
```rust
use std::iter::Peekable;

Expand Down
27 changes: 27 additions & 0 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import 'package:rust/rust.dart';

void main() {
readmeExample();
usingTheEarlyReturnKeyExample();
usingRegularPatternMatchingExample();
usingFunctionChainingExample();
Expand All @@ -12,6 +13,32 @@ void main() {
/// Visit the book to see more!
}

void readmeExample() {
final string = "kl!sd!?!";
Vec<int> answer = [];
Peekable<(int, Arr<String>)> iter = string
.chars()
.mapWindows(2, identity)
.enumerate()
.peekable();

while (iter.moveNext()) {
final (index, window) = iter.current;
switch (window) {
case ["!", "?"]:
break;
case ["!", _]:
answer.push(index);
case [_, "!"] when iter.peek().isNone():
answer.push(index + 1);
}
}
assert(answer.length == 2);
assert(answer[0] == 2);
assert(answer[1] == 7);
}


Result<int, String> usingTheEarlyReturnKeyExample() => Result(($) {
// Early Return Key
// Will return here with 'Err("error")'
Expand Down

0 comments on commit 13e3af4

Please sign in to comment.