mod test_hello;
fn main(){
test_hello::print_test();
}
And everything worked. I get "hello!".
5. Now i wanted to use the library i cloned.
6. In src/lib.rs there is a pub struct SecretKey
that im trying to access.
7. in my main.rs, i added line of code mod lib;
8. When i tried running the code, i get 60 errors. And im not sure why...
9. How can i access the SecretKey struct and call required functions i need?
If you have both a main.rs and lib.rs, then your project is actually two crates: the binary and library crate. The mod statement is used to define a new module of the current crate, so its not appropriate for accessing things from another crate. The correct way to access things in lib.rs from main.rs is by doing
use my_crate_name::ThingInLibRs;
Here, my_crate_name is the name at the top of your Cargo.toml.
As a more general point, if you ever do any of the following, then you've made a mistake:
Mention main.rs or lib.rs using a mod statement.
Mention any specific file with a mod statement more than once.
Note in particular that files in src/ may be mentioned with a mod in main.rs or in lib.rs, but not from both. If a file is needed from both, mention it only in lib.rs and use a use statement to import it from main.rs.
Thanks for the reply, i think we are getting somewhere.
So, i am trying to follow this documentation https://crates.io/crates/blst too.
In USAGE section, there it says to use for example use blst::min_pk::*
Now my main.rs in src looks like this:
use blst::min_pk::*;
fn main(){
}
First few lines of my Cargo.toml are:
[package]
name = "blst"
version = "0.3.10"
it also have includes, readme, etc...
I tried running my main.rs and im getting:
error[E0433]: failed to resolve: maybe a missing crate `blst`?
--> main.rs:1:5
|
1 | use blst::min_pk::*;
| ^^^^ maybe a missing crate `blst`?
|
= help: consider adding `extern crate blst` to use the `blst` crate
i also tried adding line:use blst::* but it didnt help...
It looks like you are trying to use blst in your own project. This isn't the way to do it.
What you should do is create your own project, in its own directory (separate from the blst directory tree), with its own Cargo.toml and its own name. Then you can add blst = "0.3.10" to the dependencies section of your Cargo.toml (as mentioned at the bottom of the crates.io page, under "Install"), or even easier do cargo add blst in your terminal. Then you can add the use statement in your files and access the items in the blst crate.