Skip to content

Commit

Permalink
doc: Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmah309 committed Jul 2, 2024
1 parent 2aa1fb8 commit bfa01b6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
9 changes: 5 additions & 4 deletions book/src/introduction/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
***
### Install

rust_core can be install like any other Dart package.
rust_core can be installed like any other Dart package.

Dart:
```shell
Expand All @@ -23,13 +23,13 @@ dependencies:
### Imports
rust_core follows the same library structure and naming as [Rust's rust_core](https://doc.rust-lang.org/core/).
rust_core follows the same library structure and naming as [Rust's core library](https://doc.rust-lang.org/core/).
To that extent, each library can be imported individually
```dart
import 'package:rust_core/result.dart';
```
or in it's entirety
or all libraries
```dart
import 'package:rust_core/rust_core.dart';
```
Expand All @@ -52,7 +52,8 @@ These types can be easily chained with other operations or pattern matched.

### The Rust `?` Operator and Early Return Key Notion

`Result<T,E>` and `Option<T>` both support early return key notation, which is a same as the rust `?` operator.
`Result<T,E>` and `Option<T>` both support early return key notation, which has
the same function as the rust `?` operator.
It returns from the scope if an `Err` or `None` is encountered, otherwise it retrieves the inner value.

Result example:
Expand Down
2 changes: 1 addition & 1 deletion book/src/libs/array/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ for(final entry in array){
}
var (slice1, slice2) = array.splitSlice(3);
```
`Arr`'s allocation will be more efficient than compare to a `List` since it does not reserve additional capacity and allocates the full amount eagerly. Which is important since allocations account for most of the cost of the runtime costs of a List.
`Arr`'s allocation will be more efficient than compared to a `List` since it does not reserve additional capacity and allocates the full amount eagerly. Which is important since allocations account for most of the cost of the runtime costs of a List.
8 changes: 3 additions & 5 deletions book/src/libs/option/option.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rust_core support nullable and `Option` implementations of classes and methods f
can easily switch between the two with `toOption` and `toNullable` (or you can use `.v` directly).

### Usage
The `Option` Type and features work very similar to [Result]. We are able to chain operations in a safe way without
The `Option` Type and features work very similar to [Result](../result/result.md). We are able to chain operations in a safe way without
needing a bunch of `if` statements to check if a value is null.

```dart
Expand All @@ -17,7 +17,7 @@ Option<double> val = intOptionFunc()
.map(halfVal);
expect(val.unwrapOr(2), 2);
```
See the [docs] for all methods and extensions.
See the [docs](https://pub.dev/documentation/rust_core/latest/option/option-library.html) for all methods and extensions.

You can also use Option in pattern matching
```dart
Expand Down Expand Up @@ -69,6 +69,4 @@ final (x, y) = optionFunc().map((e) => e + " added string").zip(Some(1)).unwrap(
With `Option` you will also never get another null assertion error again.

As in the previous example, it is strongly recommended to use `Option` type as the return type, since it allows chaining operations.
But the choice is up to the developer.

[Result]: https://github.com/mcmah309/rust_core/tree/master/lib/src/result
But the choice is up to the developer.
11 changes: 5 additions & 6 deletions book/src/libs/result/tips_and_best_practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ analyzer:
```
## ToResult and ToResultEager
***
In various circumstances you just want a single `Result` for these times, think `toResult()` or in some cases
In various circumstances you may have multiple `Result`s and just want a single `Result`.
For these times, think `toResult()` or in some cases
`toResultEager()`. These extension methods have been added to make life easier.

## Iterable Result
***
One of these is on `Iterable<Result<S,F>>`, which can turn into a
### Iterable Result
One of these situations is when you have a `Iterable<Result<S,F>>`, which can turn into a
`Result<List<S>,List<F>>`. Also, there is `.toResultEager()` which can turn into a single `Result<List<S>,F>`.

```dart
Expand All @@ -96,8 +96,7 @@ expect(result.unwrap(), [1, 2, 3]);
result = [Ok<int,int>(1), Err<int,int>(2), Ok<int,int>(3)].toResultEager();
expect(result.unwrapErr(), 2);
```
## Multiple Results of Different Success Types
***
### Multiple Results of Different Success Types
Sometimes you need to call multiple functions that return `Result`s of different types. You could write something
like this:
```dart
Expand Down
6 changes: 3 additions & 3 deletions book/src/libs/sync/channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rust_core supports two types of channels, "local" channels (same isolate) and "i
`channel` is used for communication between produces and consumers on the **same** isolate. `channel` is
similar to `StreamController` except it buffers data until read and will never throw.
In more detail, `channel` returns a `Sender` and `Receiver`. Each item `T` sent by the `Sender`
will only be seen once by the `Receiver`. If the `Sender` calls `close` while the `Receiver`'s buffer
will only be seen once by the `Receiver`. Even if the `Sender` calls `close` while the `Receiver`'s buffer
is not empty, the `Receiver` will still yield the remaining items in the buffer until empty.

### Examples
Expand Down Expand Up @@ -65,7 +65,7 @@ void main() async {
// Sender sends data and then an error
tx.send(1);
tx.send(2);
tx.addError(Exception("Test error"));
tx.sendError(Exception("Test error"));
// Receiver retrieves data and handles errors
for (int i = 0; i < 3; i++) {
Expand Down Expand Up @@ -131,7 +131,7 @@ void main() async {
`isolateChannel` is used for bi-directional isolate communication. The returned
`Sender` and `Receiver` can communicate with the spawned isolate and
the spawned isolate is passed a `Sender` and `Receiver` to communicate with the original isolate.
Each item `T` sent by the `Sender` will only be seen once by the `Receiver`. If the `Sender` calls `close` while the `Receiver`'s buffer
Each item `T` sent by the `Sender` will only be seen once by the `Receiver`. Even if the `Sender` calls `close` while the `Receiver`'s buffer
is not empty, the `Receiver` will still yield the remaining items in the buffer until empty.
Types that can be sent over a `SendPort`, as defined [here](https://api.flutter.dev/flutter/dart-isolate/SendPort/send.html),
are allow to be sent between isolates. Otherwise a `toIsolateCodec` and/or a `fromIsolateCodec` can be passed
Expand Down
1 change: 1 addition & 0 deletions book/src/misc/packages_built_on_rust_core.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

## Community
| Library | Description |
| ------- | ----------- |
| [rewind] | A logging utility that allows you completely customize what is captured and how your logs look at each logging level. |
| [thiserror] | A library for concisely defining error types (error enums / sealed classes) and their String representation. |

Expand Down

0 comments on commit bfa01b6

Please sign in to comment.