Skip to content

Commit

Permalink
Update main.sw
Browse files Browse the repository at this point in the history
  • Loading branch information
naz3eh committed Aug 16, 2024
1 parent 5de2061 commit 8e75409
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions examples/library/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
contract;

// 1. Importing within the same project
// Using "mod" keyword, you can define the library as a dependency within a program.
// Using "mod" keyword, you can import an internal library that has been defined in this project.
mod sqrt_lib;

// It is a good practice to import in ABI
// It is also a good practice to define events and custom errors using this way

// Using "use" keyword imports in a library
// use srt_lib::*;
// Using "use" keyword imports in a library. This method is used to import an external lilbray that is defined outside the main `src` directory.
// use sqrt_lib::math_sqrt;
// $ tree
// .
// ├── my_project
// │ ├── Cargo.toml
// │ ├── Forc.toml
// │ └─── src
// │ └── main.sw
// │
// └── external_lib
// ├── Cargo.toml
// ├── Forc.toml
// └─── src
// └── lib.sw
// External library is outside the src directory of our project. Thus, it needs to be added as a dependency in the Forc.toml of our project.
// [dependencies]
// external_lib = { path = "../external_lib" }


// 2. Importing the standard library
// The standard library consists of
Expand All @@ -24,6 +41,7 @@ mod sqrt_lib;
// auth::msg_sender,
// };


// 3. Importing from a different project
// If any library is not listed as a dependency, but present in forc.toml, you can use it as below.
// Math libraries copied from https://github.com/sway-libs/concentrated-liquidity/
Expand Down

0 comments on commit 8e75409

Please sign in to comment.