forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional documentation for the Sway book. (FuelLabs#478)
* Add custom types documentation and update roadmap. * Add information on the turbofish; format markdown * Updating sway types & rename colored coins. (FuelLabs#481) * Update Address and ContractID types * Rename colored coins * Cleanup markdown * Move Address and ContractId types to new book section * Update SUMMARY.md * Remove colored-coins * Fixup * Update docs/src/advanced/generic_types.md Co-authored-by: John Adler <adlerjohn@users.noreply.github.com> * Update docs/src/advanced/generic_types.md Co-authored-by: John Adler <adlerjohn@users.noreply.github.com> * More doc updates (FuelLabs#501) * fmt * New language server. * Add basics page index. * Index updates. * Update index. * Update readme. * Update install docs. * Clean up Forc project intro. * Skeleton for why sway. * Fix location of Cargo.toml. (FuelLabs#502) * WIP storage docs * docs on reference types and purity: wip Co-authored-by: Nick Furfaro <nfurfaro33@gmail.com> Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
- Loading branch information
1 parent
6933c95
commit b42d016
Showing
28 changed files
with
522 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# Advanced Concepts | ||
|
||
Advanced concepts. | ||
|
||
- [Generic Types](./generic_types.md) | ||
- [Traits](./generic_types.md) | ||
- [Traits](./traits.md) | ||
- [Trait Constraints](./trait_constraints.md) | ||
- [Assembly](./assembly.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# Trait Constraints | ||
|
||
Trait constraints on generics are currently a work in progress. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Blockchain Types | ||
|
||
Sway has a selection of types provided via the standard library (`lib-std`) which both add a degree of type-safety, as well as make the intention of the developer more clear. | ||
|
||
## Address type | ||
|
||
The `Address` type is a type-safe wrapper around the primitive `b256` type. Unlike Ethereum, an address **never** refers to a deployed smart contract (see the `ContractId` type below). An `Address` can be either the hash of a public key (An Externally Owned Address if you're coming from Ethereum) or the hash of a [predicate](../sway-on-chain/predicates.md). | ||
|
||
```sway | ||
pub struct Address { | ||
value: b256, | ||
} | ||
``` | ||
|
||
Casting between the `b256` & `Address` types must be done explicitly: | ||
|
||
```sway | ||
let my_number: b256 = 0x000000000000000000000000000000000000000000000000000000000000002A; | ||
let my_address: Address = ~Address::from(my_number); | ||
let forty_two: b256 = my_address.into(); | ||
``` | ||
|
||
## ContractId type | ||
|
||
The `ContractId` type is a type-safe wrapper around the primitive `b256` type. A contract's id is a unique, deterministic identifier analogous to a contract's address on Ethereum. | ||
|
||
```sway | ||
pub struct ContractId { | ||
value: b256, | ||
} | ||
``` | ||
|
||
Casting between the `b256` & `ContractId` types must be done explicitly: | ||
|
||
```sway | ||
let my_number: b256 = 0x000000000000000000000000000000000000000000000000000000000000002A; | ||
let my_contract_id: ContractId = ~ContractId::from(my_number); | ||
let forty_two: b256 = my_contract_id.into(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.