I created a new internal library by following the sway docs, but I have the issue whenever I try to import it to main.sw and forc build
I receive this error
mod internal_lib; | ^^^ Expected an item. 4 | 5 | use internal_lib::Organisation;
This is the library I created:
library;
use std::storage::storage_vec::*;
pub struct Organisation {
owner: str[40],
sellers: StorageVec<str[40]>,
}
impl Organisation {
pub fn new(owner: str) -> Self {
Self {
owner,
}
}
}
Hi there!
Can you add the code where you are importing the lib and the version of the compiler you are working with?
fuelup show
Hi, thanks for the quick response!
the import:
`mod internal_lib;
use internal_lib::Organisation;`
the version:
`Default host: x86_64-unknown-linux-gnu
fuelup home: /home/timotej/.fuelup
installed toolchains
beta-2-x86_64-unknown-linux-gnu
beta-3-x86_64-unknown-linux-gnu
latest-x86_64-unknown-linux-gnu
test_toolchain (default)
active toolchain
test_toolchain (default)
forc : 0.35.3
- forc-client
- forc-deploy : 0.35.3
- forc-run : 0.35.3
- forc-doc : 0.35.3
- forc-explore - not found
- forc-fmt : 0.35.3
- forc-index - not found
- forc-lsp : 0.35.3
- forc-tx : 0.35.3
- forc-wallet : 0.2.2
fuel-core - not found
fuel-indexer - not found
fuels versions
forc : 0.36`
Hey @timotejGerzelj thanks for the question! Can you please try the following? I was able to build your files fine after these steps. Note I had to resolve a few issues with your internal_lib.sw file.
$ fuelup self update
which grabs the latest version of fuelup
$ fuelup default latest
which sets the tool chain to the one you just got
This is the toolchain im running
β lib-import fuelup show
Default host: aarch64-apple-darwin
fuelup home: /Users/calldelegation/.fuelup
installed toolchains
--------------------
beta-3-aarch64-apple-darwin
latest-aarch64-apple-darwin (default)
latest-2023-02-18-aarch64-apple-darwin
latest-2023-04-12-aarch64-apple-darwin
active toolchain
-----------------
latest-aarch64-apple-darwin (default)
forc : 0.42.0
- forc-client
- forc-deploy : 0.42.0
- forc-run : 0.42.0
- forc-doc : 0.42.0
- forc-explore : 0.28.1
- forc-fmt : 0.42.0
- forc-index : 0.17.3
- forc-lsp : 0.42.0
- forc-tx : 0.42.0
- forc-wallet : 0.2.3
fuel-core : 0.18.3
fuel-indexer : 0.17.3
fuels versions
---------------
forc : 0.43
forc-wallet : 0.43.0
Project structure
.
βββ src/
βββ internal_lib.sw
βββ main.sw
main.sw
contract;
mod internal_lib;
use ::internal_lib::Organisation;
abi MyContract {
fn test_function() -> bool;
}
impl MyContract for Contract {
fn test_function() -> bool {
true
}
}
internal_lib.sw
library;
use std::storage::storage_vec::*;
pub struct Organisation {
owner: str[40],
sellers: StorageVec<str[40]>,
}
impl Organisation {
pub fn new(owner: str[40], sellers: StorageVec<str[40]>) -> Self {
Self {
owner,
sellers
}
}
}
1 Like
Hey @calldelegation thanks alot, this worked!
1 Like
fsy412
July 13, 2023, 2:50pm
6
maybe itβs pub fn new(owner: str[40]) β Self {
system
Closed
August 3, 2023, 10:51am
7
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.