suhari
1
hi,
i have a module m with 2 sub-modules s1 and s2 with paths
crate::m::s1
crate::m::s2
module s2 contains a variable named x
my crate is named kop
inside module s1 i can do
crate::m::s2::x // use x contained in module s2 from module s1
however instead i would like to use the crate name "kop" to write
kop::m::s2::x
can this be done?
thx
Inside of s1
, you can write:
use crate as kop;
and then you can refer to kop::m::s2::x
.
2 Likes
suhari
3
many thx!
can this be done on a global level? so that i don't have to write "use crate as kop;" in every submodule?
CAD97
4
Yes, you can use extern crate self as name;
in your lib.rs
to add name
to the prelude of names available anywhere in your crate.
2 Likes
system
Closed
6
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.