sway icon indicating copy to clipboard operation
sway copied to clipboard

Expand `Examples` in the `Sway Book`

Open Braqzen opened this issue 3 years ago • 0 comments

Summary

The current examples section contains a few small... examples which do not demonstrate the common usage of the language but instead something a little closer to mini-contracts. The examples section should be easily searchable by a user to see how to perform common operations in Sway such as importing & dependency management, looping etc. and thus the current examples should be removed (and perhaps placed elsewhere).

This issue is meant to be an epic used to track the subtasks below.

Sections on how to:

  • [ ] Log
  • [ ] Get the msg_sender(), msg_asset_id() & msg_amount()
  • [ ] Looping
  • [ ] Mut vs immutable variables
  • [ ] Implicit vs explicit returns
  • [ ] Safety (require() / revert())
  • [ ] impl a comparison on a custom data structure e.g. the Eq trait
  • [ ] Match vs if let
  • [ ] Token operations such as transferring to contract / output, minting / burning, checking contract balance
  • [ ] Difference between the Address namespace and ContractId + Identity as the wrapper
  • [ ] Enums e.g. Option & Result
  • [ ] Project management e.g. dependencies in Forc.toml vs splitting up files in the same project and using dep to import
  • [ ] impl ABI methods
  • [ ] Storage manipulation

If there are additional important sections then feel free to edit / comment so that this description can be expanded.

Note that some of these may already exist in the Sway Book however they are in separate sections. We should unify all relevant examples into 1 section which the user can easily navigate rather than scattering them throughout the book.

Braqzen avatar Aug 02 '22 13:08 Braqzen