OK, I'm totally new to Rust. I'm evaluating Rust for a coming project, and I've run simple test programs.
I'm stuck on the simplest question ever. I use VSC. I'm adding source files to the src folder, but they won't get included in my build. If main.rs calls a function in function.rs, I'll the following get build error:
--> src\main.rs:3:5
|
3 | function( 1 );
| ^^^^^^^^ not found in this scope
Believe it or not, but the trick to adding source files to a project is nowhere described!
Btw, the title of you post seems a bit misleading. What does adding source files to the project have to do with adding source files to the version control system?
EDIT
Sorry I misread😂 I guess VSC is visual studio code?
Maybe not: the title did say "VCS"; I changed it to "VSC" to match the post body because this did seem to be about an IDE (I too guess VSC is Visual Studio Code) and not a version control system.
if you want to just include another rust code file, like you would in C, you can use the include! macro.
// foo.rs
fn foo() {
println!("foo");
}
// main.rs
include!("foo.rs"); // this literally inserts the contents of foo.rs at this point
fn main() {
foo();
}
// foo.rs, same as before
fn foo() {
println!("foo");
}
// main.rs
mod foo; // we declare the module foo, only main.rs, lib.rs and mod.rs files can declare modules
fn main() {
foo::foo() // we need to use `foo::` here, because the contents of foo.rs are scoped under the module
}
But what you should be doing is using cargo (which it looks like you aren't).
it manages dependencies, versioning, publishing and a bunch of other stuff.
@SebastianJL: VSC means Visual Studio Code, indeed. The title is misleading because VSC has nothing to do with this, only the code. But I didn't know that when I posted the question.