Skip to content

Commit 5e87318

Browse files
authored
Merge branch 'master' into xunilrj/typed-tree-array-repeat
2 parents cef551a + 0640dbe commit 5e87318

File tree

90 files changed

+5672
-451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+5672
-451
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ jobs:
475475
run: cargo run --locked --release -p forc -- build --experimental storage_domains --release --locked --path ./test/src/sdk-harness
476476
- name: Cargo Test sway-lib-std - Experimental Feature 'storage_domains'
477477
run: cargo test --locked --release --manifest-path ./test/src/sdk-harness/Cargo.toml -- --nocapture
478+
- name: Build All Tests - Experimental Feature 'error_type'
479+
run: cargo run --locked --release -p forc -- build --experimental error_type --release --locked --path ./test/src/sdk-harness
480+
- name: Cargo Test sway-lib-std - Experimental Feature 'error_type'
481+
run: cargo test --locked --release --manifest-path ./test/src/sdk-harness/Cargo.toml -- --nocapture
478482

479483
forc-run-benchmarks:
480484
runs-on: buildjet-4vcpu-ubuntu-2204
@@ -541,14 +545,20 @@ jobs:
541545
run: forc build --path sway-lib-core && forc test --path sway-lib-core
542546
- name: Run Core Unit Tests - Experimental feature 'storage_domains'
543547
run: forc build --experimental storage_domains --path sway-lib-core && forc test --experimental storage_domains --path sway-lib-core
548+
- name: Run Core Unit Tests - Experimental feature 'error_type'
549+
run: forc build --experimental error_type --path sway-lib-core && forc test --experimental error_type --path sway-lib-core
544550
- name: Run Std Unit Tests
545551
run: forc build --path sway-lib-std && forc test --path sway-lib-std
546552
- name: Run Std Unit Tests - Experimental feature 'storage_domains'
547553
run: forc build --experimental storage_domains --path sway-lib-std && forc test --experimental storage_domains --path sway-lib-std
554+
- name: Run Std Unit Tests - Experimental feature 'error_type'
555+
run: forc build --experimental error_type --path sway-lib-std && forc test --experimental error_type --path sway-lib-std
548556
- name: Run In Language Unit Tests
549557
run: forc build --path test/src/in_language_tests && forc test --path test/src/in_language_tests
550558
- name: Run In Language Unit Tests - Experimental feature 'storage_domains'
551559
run: forc build --experimental storage_domains --path test/src/in_language_tests && forc test --experimental storage_domains --path test/src/in_language_tests
560+
- name: Run In Language Unit Tests - Experimental feature 'error_type'
561+
run: forc build --experimental error_type --path test/src/in_language_tests && forc test --experimental error_type --path test/src/in_language_tests
552562

553563
forc-pkg-fuels-deps-check:
554564
runs-on: buildjet-4vcpu-ubuntu-2204

Cargo.lock

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ etk-ops = { package = "fuel-etk-ops", version = "0.3.1-dev" }
140140
extension-trait = "1.0"
141141
fd-lock = "4.0"
142142
filecheck = "0.5"
143+
flate2 = "1.0"
143144
fs_extra = "1.2"
144145
futures = { version = "0.3", default-features = false }
145146
gag = "1.0"

docs/book/spell-check-custom-words.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,8 @@ FuelLabs
237237
github
238238
toml
239239
hardcoded
240-
subdirectories
240+
subdirectories
241+
RawSlice
242+
StringArray
243+
StringSlice
244+
calldata

docs/book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
- [forc deploy](./forc/plugins/forc_client/forc_deploy.md)
100100
- [forc run](./forc/plugins/forc_client/forc_run.md)
101101
- [forc submit](./forc/plugins/forc_client/forc_submit.md)
102+
- [forc call](./forc/plugins/forc_client/forc_call.md)
102103
- [forc crypto](./forc/plugins/forc_crypto.md)
103104
- [forc debug](./forc/plugins/forc_debug.md)
104105
- [forc doc](./forc/plugins/forc_doc.md)

docs/book/src/advanced/traits.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,43 @@ trait MyTrait {
134134

135135
Check the `associated types` section on [associated types](./associated_types.md) page.
136136

137+
## Trait Constraints
138+
139+
When writing generic code, you can constraint the choice of types for a generic argument by using the `where` keyword. The `where` keyword specifies which traits the concrete generic parameter must implement. In the below example, the function `expects_some_trait` can be called only if the parameter `t` is of a type that has `SomeTrait` implemented. To call the `expects_both_traits`, parameter `t` must be of a type that implements _both_ `SomeTrait` and `SomeOtherTrait`.
140+
141+
```sway
142+
trait SomeTrait { }
143+
trait SomeOtherTrait { }
144+
145+
fn expects_some_trait<T>(t: T) where T: SomeTrait {
146+
// ...
147+
}
148+
149+
fn expects_some_other_trait<T>(t: T) where T: SomeOtherTrait {
150+
// ...
151+
}
152+
153+
fn expects_both_traits<T>(t: T) where T: SomeTrait + SomeOtherTrait {
154+
// ...
155+
}
156+
```
157+
158+
## Marker Traits
159+
160+
Sway types can be classified in various ways according to their intrinsic properties. These classifications are represented as marker traits. Marker traits are implemented by the compiler and cannot be explicitly implemented in code.
161+
162+
E.g., all types whose instances can be used in the `panic` expression automatically implement the `Error` marker trait. We can use that trait, e.g., to specify that a generic argument must be compatible with the `panic` expression:
163+
164+
```sway
165+
fn panic_with_error<E>(err: E) where E: Error {
166+
panic err;
167+
}
168+
```
169+
170+
> **Note** `panic` expression and error types [have not yet been implemented](https://github.com/FuelLabs/sway/issues/6765)
171+
172+
All marker traits are defined in the `core::marker` module.
173+
137174
## Use Cases
138175

139176
### Custom Types (structs, enums)
@@ -160,8 +197,6 @@ fn play_game_with_deck<T>(a: Vec<T>) where T: Card {
160197
}
161198
```
162199

163-
> **Note** Trait constraints (i.e. using the `where` keyword) [have not yet been implemented](https://github.com/FuelLabs/sway/issues/970)
164-
165200
Now, if you want to use the function `play_game_with_deck` with your struct, you must implement `Card` for your struct. Note that the following code example assumes a dependency _games_ has been included in the `Forc.toml` file.
166201

167202
```sway

0 commit comments

Comments
 (0)