#import modules and function
37 messages · Page 1 of 1 (latest)
What program produced that second chart? If it's accurate then you have two mistakes here:
- You have declared doubly-nested modules. You should not write
mod file_extensioninside offile_extension.rs; there should only be onemodin your entire project per module. FileExtensionis notpub, so it can't be used outside of thefile_extensionmodule. You need to writepub enum FileExtensionorpub(crate) enum FileExtension
Sorry for the late replay;
this is cargo modules, cargo modules structure --lib
about the first state you said, i don't have any file_extensions.rs , i have a directory with name file_extension, mod file_extension is declared inside mod.rs
that's the mistake
you have a mod file_extension; and a mod file_extension {. that makes you have two modules with the same name, nested
you do not declare modules inside of modules.
you should have only one mod per module you intend to have. it can be a mod foo; or a mod foo {, but you don't use both
mod file_extension; is inside lib.rs
that's good.
do i remove it?
no, you get rid o the mod file_extension {} that is inside file_extension/mod.rs
that is the extra module that you do not need.
but then i wouldn't have a module, right?
no, mod file_extension; declares the module you want to have.
the contents of the module go directly in the corresponding file, file_extension/mod.rs
please bare with me i'm new to rust
you do not also re-declare the module inside the file
you declare modules only once. not twice.
the string mod file_extension should appear in your program only once.
you do not need to declare the module once in lib.rs and again inside itself. that just makes two modules.
ohh so it is automatically a module?
when you write mod file_extension;, with a ; instead of a {} you are saying: "please get the contents of this module from file_extension/mod.rs or from file_extension.rs"
your source files contain the contents of modules.
to be honest i'm more confused than ever, can i send you the repo link and tell me how can i declare the thing correctly?
yeah sure
it looks like you did the right thing to file_extension/mod.rs
https://github.com/AymaneImr/just_testing/blob/main/src/file_extension/table_structure.rs has the same problem, it has an extra mod table_structure {} in it
once you have fixed that too, you can do use super::FileExtension; inside table_structure.rs, and be able to use FileExtension::open_csv(). But, actually, maybe that function shouldn't be inside impl FileExtension? It doesn't use FileExtension at all.
then the path would be just super::open_csv or crate::file_extension::open_csv
mate thank you so much you saved me
now i understand those mistakes very well, i solved everything and now i'm able to call open_csv just as i wanted
yeah that's right i'm gonna improve it for sure
thanks man i appreciate your help