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 97d2822 commit 535725a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void main() {
.enumerate()
.peekable();
while (iter.moveNext()) {
final (int index, Arr<String> window) = iter.current;
final (index, window) = iter.current;
switch (window) {
case ["!", "?"]:
break;
Expand Down
4 changes: 1 addition & 3 deletions book/src/introduction/new_to_dart.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
Welcome to Dart!

Dart is a great language choice for fast cross platform development and scripting.

rust_core is great start to learn the Dart semantics as you will feel like you are writing native rust.

You'll find that rust_core is great start to learn Dart's semantics as you will feel like you are writing native rust.
rust_core will introduce you to a few new types you may find useful as a Dart developer:

| Rust Type | Dart Equivalent | rust_core | Description |
Expand Down
2 changes: 0 additions & 2 deletions book/src/introduction/new_to_rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ Welcome to Rust!

Maybe you have heard of Rust and want to see what all the hype is about, maybe you know a little Rust
and want to improve your Rust while writing Dart, for whatever the reason, rust_core is here to help.

Rust has a solid reputation for writing safe, maintainable, and performant code. rust_core is great start to learn and improve your rust semantics/knowledge. You will write Dart and learn Rust along the way.

With rust_core you can expect all the usual types you see in Rust. Here is a quick matrix
comparing Rust, Dart, and Dart with rust_core:

Expand Down
27 changes: 13 additions & 14 deletions book/src/introduction/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import 'package:rust_core/rust_core.dart';
```
## General Notes

All of rust_core's classes and methods are well documented [docs](https://pub.dev/documentation/rust_core/latest/), but
being an implementation of Rust's core library, you can also refer the the [Rust core](https://doc.rust-lang.org/beta/core/index.html) if anything is unclear.
All of rust_core's classes and methods are well documented in the [docs](https://pub.dev/documentation/rust_core/latest/), but
being an implementation of Rust's core library, you can also refer to [Rust core](https://doc.rust-lang.org/beta/core/index.html) if anything is unclear.
The functionally is the same.

## The Basics
Expand All @@ -45,21 +45,21 @@ The functionally is the same.
`Result<T, E>` is the type used for returning and propagating errors.

`Option<T>` represents a value that can be either some value of type `T` (`Some<T>`) or `None`.
It is used "in place" of `null` (implemented as a zero cost extension type of `T?`).
It is used "in place" of `T?` (implemented as a zero cost extension type of `T?`).

These types can be easily chained with other operations.

### 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 - It returns from
the scope if an [Err] or `None` is encountered, otherwise it retrieves the inner value.
`Result<T,E>` and `Option<T>` both support early return key notation, which is a same as the rust `?` operator.
It returns from the scope if an `Err` or `None` is encountered, otherwise it retrieves the inner value.

Result example:
```dart
Result<double, String> divedBy(int num, int divisor) => divisor == 0 ? Err("Divide by zero error") : Ok(num / divisor);
Result<double, String> divideBy(int num, int divisor) => divisor == 0 ? Err("Divide by zero error") : Ok(num / divisor);
Result<double, String> func(int x) => Result(($) { // Early Return Key
// The function will return here
int val = divedBy(x, 0)[$] + 10;
int val = divideBy(x, 0)[$] + 10;
return Ok(val);
});
Expand All @@ -70,12 +70,12 @@ Result<double, String> func(int x) => Result(($) { // Early Return Key

### `List` and `Arr`

`Arr` is a compliment to `List`, which represents a fixed sized `List`. No more runtime exceptions for trying to grow
a non-growable `List`. It also has zero runtime cost, as it is an extension type of `List`. `Arr` is more efficient than a growable `List`.
`Arr` (array) is a compliment to `List`, representing a fixed sized `List`. Having a separate `Arr` type fixes runtime exceptions for trying to grow
a non-growable `List`. It also has zero runtime cost, as it is an extension type of `List` and is more efficient than a growable `List`. With `Arr`, type intent is clear for maintainers and developers are able think about code performance more critically.

#### Iter
rust_core implements the entirety of Rust's stable and unstable [Iterator](https://doc.rust-lang.org/beta/core/iter/trait.Iterator.html) methods.
There are a lot of methods here that many Dart developers may not be familiar with. Definitely worth a look - [pub](https://pub.dev/documentation/rust_core/latest/iter/iter-library.html)
There are a lot of methods here that many Dart developers may not be familiar with. Definitely worth a look - [docs](https://pub.dev/documentation/rust_core/latest/iter/iter-library.html)

```dart
List<int> list = [1, 2, 3, 4, 5];
Expand All @@ -94,19 +94,18 @@ check [here](../libs/iter/iter.md) for more info.
#### Slice

A `Slice` is a contiguous sequence of elements in a `List` or `Arr`. Slices are a view into a list without allocating and copying to a new list,
thus slices are more efficient than creating a sub-list with `list.sublist(x,y)`.
thus slices are more efficient than creating a new `List` with `.sublist()` e.g. `list.sublist(x,y)`.
```dart
var list = [1, 2, 3, 4, 5];
var slice = Slice(list, 1, 4);
slice = list.slice(1,4); // alternative
var slice = Slice(list, 1, 4); // or `list.slice(1,4)`
expect(slice, [2, 3, 4]);
var taken = slice.takeLast();
expect(taken, 4);
expect(slice, [2, 3]);
slice[1] = 10;
expect(list, [1, 2, 10, 4, 5]);
```
`Slice` also has <u>a lot</u> of efficient methods for in-place mutation within and between slices.
`Slice` also has <u>a lot</u> of efficient methods for in-place mutation within and between slices - [docs](https://pub.dev/documentation/rust_core/latest/slice/slice-library.html)

## Whats Next?

Expand Down
4 changes: 2 additions & 2 deletions lib/src/sync/isolate_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class IsolateReceiver<T> extends LocalReceiver<T> {
/// 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
/// to encode and decode the messages.
Future<(IsolateSender<T> tx1, IsolateReceiver<U> rx1)> isolateChannel<T, U>(
FutureOr<void> Function(IsolateSender<U> tx2, IsolateReceiver<T> rx2) func,
Future<(IsolateSender<T> tx, IsolateReceiver<U> rx)> isolateChannel<T, U>(
FutureOr<void> Function(IsolateSender<U> tx, IsolateReceiver<T> rx) func,
{SendCodec<T>? toIsolateCodec,
SendCodec<U>? fromIsolateCodec}) async {
final receiveFromIsolate = RawReceivePort();
Expand Down

0 comments on commit 535725a

Please sign in to comment.