File not found Error

Hi,i am new to Rust programming language.
I have three files a.rs,b.rs,c.rs. a.rs is the main file in where my main function exist.
In c.rs ,structure declaration and definition is there.In b.rs file i am using the c.rs file by calling "mod c" but compiler throws error by saying file c does not exist.
Any one please help me to sort out this issue.
Thanks in advance

You need to put the mod c; declaration in your main.rs or lib.rs. To access it from b.rs, you can use use crate::c::MyStruct;.

If you put mod c; in b.rs, it will look for the file src/b/c.rs

i want to use the structure defined in c.rs file in the b.rs file

Sure, so do like I described.

// src/main.rs or src/lib.rs
mod b;
mod c;
// src/c.rs
pub struct MyStruct {}
// src/b.rs
use crate::c::MyStruct;

It throws an error as use of undeclared type or module c

Please post the full error.

You access it with crate::c, not with just c. Additionally, what is value?

value is the structure variable

You can't really define mutable global variables in Rust.

Hi Thanks for your support .it's compiling now.
But still i didn't understand the usage of crate.

The word crate refers to your own project.

// Standard library
use std::some::thing;

// Your project
use crate::your::thing;
1 Like

You can't really define mutable global variables in Rust.

is it possible to use Global structure variable in Rust like c programming Lnguage???

There are some ways but if you are new to the language, I suggest you don't do it.

Thanks,

If i want to modify the data of the single structure in different files.Then what is the best method to do so.can u give me a better suggestion??/

You can pass a reference to it as an argument.

Thanks

For starters ...any reference books???

The Rust book talks about references in chapter four.

1 Like

I did not configure the Cargo.toml file..

I am using Linux system ,i created one folder in that folder i created a.rs,b.rs,c.rs files
and i compile the a.rs file using rustc a.rs....