Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Merge sway reference section into the sway book #6492

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions docs/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
- [Behavior Considered Undefined](./reference/undefined_behavior.md)
- [Differences From Solidity](./reference/solidity_differences.md)
- [Differences From Rust](./reference/rust_differences.md)
- [Storage](./reference/storage/storage.md)
- [Initialization](./reference/storage/init.md)
- [Reading & Writing](./reference/storage/read-write.md)
- [Libraries](./reference/storage/libraries/index.md)
Comment on lines +77 to +79
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this error means you can't have these links nested here:

AssertionError [ERR_ASSERTION]: cannot nest subfolders in SUMMARY.md

Suggested change
- [Initialization](./reference/storage/init.md)
- [Reading & Writing](./reference/storage/read-write.md)
- [Libraries](./reference/storage/libraries/index.md)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update the failing checks

- [Contributing To Sway](./reference/contributing_to_sway.md)
- [Keywords](./reference/keywords.md)
- [Forc Reference](./forc/index.md)
Expand Down
29 changes: 29 additions & 0 deletions docs/book/src/reference/known_issues_and_workarounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@

* [#1182](https://github.com/FuelLabs/sway/issues/1182) Arrays in a `storage` block are not yet supported. See the [Manual Storage Management](../advanced/advanced_storage.md#manual-storage-management) section for details on how to use `store` and `get` from the standard library to manage storage slots directly. Note, however, that `StorageMap<K, V>` _does_ support arbitrary types for `K` and `V` without any limitations.


## Importing

In [external libraries](../../language/program-types/libraries/external.md) we have looked at how a library can be imported into a project so that code can be reused.

When it comes to importing only external libraries can be imported through the `Forc.toml` file; any other type of program will result in an error.

This means that the following projects cannot be imported:

- [contracts](../../language/program-types/contract.md)
- [internal libraries](../../language/program-types/libraries/internal.md)
- [scripts](../../language/program-types/script.md)
- [predicates](../../language/program-types/predicate.md)

While contracts cannot be imported, a workaround is to move the contract's `abi` declaration into an [external library](../../language/program-types/libraries/external.md) and import that library anywhere the ABI is needed.

## Pattern Matching

### Nested Match Expressions

In [nested match expressions](../../language/control-flow/match/complex/nested-expression.md) we nest a `match` expression by embedding it inside the `{}` brackets on the right side of the arrow `=>`.

Match expressions cannot be used as a pattern, the left side of the arrow `=>`.

### Constants

When matching on [constants](../../language/control-flow/match/complex/constant.md) we specify that a constant must be used in order to match on a variable. Dynamic values, such as an argument to a function, cannot be matched upon because it will be treated as a [`catch_all`](../../language/control-flow/match/single-line.md) case and thus any subsequent patterns will not be checked.


## General

* No compiler optimization passes have been implemented yet, therefore bytecode will be more expensive and larger than it would be in production. Note that eventually the optimizer will support zero-cost abstractions, avoiding the need for developers to go down to inline assembly to produce optimal code.
11 changes: 11 additions & 0 deletions docs/book/src/reference/storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Storage

A [smart contract](../../language/program-types/contract.md) is able to perform computation and store & manipulate data over time.

In the following sections we'll take a look at how Sway handles `storage` through:

- [Storage Initialization](init.md): How to declare a `storage` block
- [Reading & Writing](read-write.md): How to read from and write to storage
- [Libraries](libraries/index.md): Additional functionality provided by the [storage library](https://github.com/FuelLabs/sway/blob/master/sway-lib-std/src/storage.sw)
- [Namespaces](namespace.md): How to use `storage` namespaces
- [In keyword](in-keyword.md): How to override storage variable position
Loading