You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The sway-libs repository currently uses workspaces to organize each library. This separates each library into its own project and allows for each library to be imported using only the library name. This does however comes with a major downside, being that each library must be imported individually.
For example, here we would like to use 3 different libraries; StorageString, String, and Ownership. Adding these as dependencies would look like the following:
[dependencies]
string = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.8.1"}
ownership = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.8.1"}
storage_string = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.8.1"}
## Type of change
<!--Delete points that do not apply-->
- Improvement (refactoring, restructuring repository, cleaning tech
debt, ...)
## Changes
The following changes have been made:
- All imports have changed from multiple imports to a single imports
using the following:
```sway
libraries = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.4.0" }
```
From there your desired library may be imported:
```sway
use libraries::ownership::only_owner;
```
- Many of the primary functions have been moved out of the library's
folder. The documentation for this will be moved into a book in a follow
up PR.
- There are a number of private modules that are now exposed until
FuelLabs/sway#5765 is resolved.
## Notes
- This should get `forc doc` to produce a single document containing all
libraries rather than multiple documents for each library.
## Related Issues
<!--Delete everything after the "#" symbol and replace it with a number.
No spaces between hash and number-->
Closes#141
Motivation
Description
Issue
The sway-libs repository currently uses workspaces to organize each library. This separates each library into its own project and allows for each library to be imported using only the library name. This does however comes with a major downside, being that each library must be imported individually.
For example, here we would like to use 3 different libraries; StorageString, String, and Ownership. Adding these as dependencies would look like the following:
Our Sway contract would then import these as so:
Proposed Change
Instead, if we organize the repository akin to the std lib with a root
Forc.toml
file, we would have the following dependencies and imports:Motivation
As more libraries are introduced, it may make sense to move away from workspaces to reduce the number of individual imports.
The text was updated successfully, but these errors were encountered: