From ebc2ee6bf5d488e0ff693bfc8680707d66cd5392 Mon Sep 17 00:00:00 2001 From: Call Delegation <106365423+calldelegation@users.noreply.github.com> Date: Mon, 15 Jul 2024 04:23:08 -0400 Subject: [PATCH] docs: Add Core Library to introduction section of the Sway book (#6193) ## Description https://fuellabs.slack.com/archives/C031TTYJM60/p1719402172570099 ## Checklist - [ ] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: IGI-111 --- docs/book/spell-check-custom-words.txt | 7 ++++- docs/book/src/SUMMARY.md | 1 + docs/book/src/introduction/core_library.md | 30 ++++++++++++++++++++++ docs/book/src/introduction/index.md | 1 + 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 docs/book/src/introduction/core_library.md diff --git a/docs/book/spell-check-custom-words.txt b/docs/book/spell-check-custom-words.txt index 818c9a71b02..0d66d348464 100644 --- a/docs/book/spell-check-custom-words.txt +++ b/docs/book/spell-check-custom-words.txt @@ -210,4 +210,9 @@ namespacing unsafety prioritizations polymorphism -ContractId \ No newline at end of file +ContractId +booleans +underflows +Codec +bool +str \ No newline at end of file diff --git a/docs/book/src/SUMMARY.md b/docs/book/src/SUMMARY.md index 78f0164d676..a1c7f9edd51 100644 --- a/docs/book/src/SUMMARY.md +++ b/docs/book/src/SUMMARY.md @@ -7,6 +7,7 @@ - [The Fuel Toolchain](./introduction/fuel_toolchain.md) - [A Forc Project](./introduction/forc_project.md) - [Standard Library](./introduction/standard_library.md) + - [Core Library](./introduction/core_library.md) - [Sway Language Standards](./introduction/sway_standards.md) - [Examples](./examples/index.md) - [Counter](./examples/counter.md) diff --git a/docs/book/src/introduction/core_library.md b/docs/book/src/introduction/core_library.md new file mode 100644 index 00000000000..314db3e5c02 --- /dev/null +++ b/docs/book/src/introduction/core_library.md @@ -0,0 +1,30 @@ +# Core Library + +The Sway Core Library, like the name suggests contains core operators and logic for the primitive types of the Sway programming language. These traits and methods are an extension of the [primitive types](https://docs.fuel.network/docs/sway/basics/built_in_types/#primitive-types) `u8`, `u16`, `u32`, `u64`, `u256`, `str[]`, `str`, `bool` and , `b256` and can be used where appropriate. + +The latest core library documentation can be found [here](https://fuellabs.github.io/sway/master/core/). If the latest version is not compatible please refer to the appropriate tagged release. + +## Using the Core Library + +Core library functionalities do not need to be explicitly imported and will work out of the box after creating any new Sway project with [`forc new`](../forc/commands/forc_new.md). The `use` keyword is simply not required. + +Consider this example of using the modulo function for two like value types: + +```sway +let val_1 = 10; +let val_2 = 2; +let result = val_1 % val_2; +``` + +## Core Library Prelude + +The prelude contains a list of operations essential to all Sway programs. The latest version of the prelude can be found [here](https://github.com/FuelLabs/sway/blob/master/sway-lib-core/src/prelude.sw). + +- [`core::primitives::*`](https://github.com/FuelLabs/sway/blob/master/sway-lib-core/src/primitives.sw) +- [`core::primitive_conversions::*`](https://github.com/FuelLabs/sway/blob/master/sway-lib-core/src/primitive_conversions.sw) +- [`core::raw_ptr::*`](https://github.com/FuelLabs/sway/blob/master/sway-lib-core/src/raw_ptr.sw) +- [`core::raw_slice::*`](https://github.com/FuelLabs/sway/blob/master/sway-lib-core/src/raw_slice.sw) +- [`core::ops::*`](https://github.com/FuelLabs/sway/blob/master/sway-lib-core/src/ops.sw) +- [`core::storage::*`](https://github.com/FuelLabs/sway/blob/master/sway-lib-core/src/storage.sw) +- [`core::str::*`](https://github.com/FuelLabs/sway/blob/master/sway-lib-core/src/str.sw) +- [`core::codec::*`](https://github.com/FuelLabs/sway/blob/master/sway-lib-core/src/codec.sw) diff --git a/docs/book/src/introduction/index.md b/docs/book/src/introduction/index.md index 8328fdaf1ba..33694f3f541 100644 --- a/docs/book/src/introduction/index.md +++ b/docs/book/src/introduction/index.md @@ -6,4 +6,5 @@ To get started with Forc and Sway smart contract development, install the Fuel t - [The Fuel Toolchain](./fuel_toolchain.md) - [A Forc Project](./forc_project.md) - [Standard Library](./standard_library.md) +- [Core Library](./core_library.md) - [Sway Language Standards](./sway_standards.md)