How can I access a variable from an external file in rust? How should I import/export it?

  Kiến thức lập trình

At the root folder of my project I have the main file, with a subfolder called “others” with its respective file, I want to learn how to use variables from files in that same folder, as well as in the files in the same folder as in the main file, how should it be done in both cases? I know how to import functions but not much more than that.

I tried importing it in the same way as a function but it didn’t work

file 2:

let x = 2;

file 1:

use others::{so_dumb::x};

pub fn my_function() {


New contributor

youcraft 200 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.