Modules
Last updated
Last updated
Use pub
keyword to make items public.
Use use
keyword to brings a path into scope.
Use as
keyword to make alias for a path that brought to scope by using use
.
A path can take two forms:
An absolute path is the full path starting from a crate root; for code from an external crate, the absolute path begins with the crate name, and for code from the current crate, it starts with the literal crate
.
A relative path starts from the current module and uses self
, super
, or an identifier in the current module.
References:
This exercise is simple we just need to make the make_sausage
function accessible from main function but not the get_secret_recipe
function.
We can do this by adding pub
before fn make_sausage()
.
In this exercise the TODO
stated that we need to complete the use
syntax below:
So we can conclude that we need to re-export the constant PEAR
as fruit
and CUCUMBER
as veggie
.
Don forget to add pub
so it's accessible in main function.
In this exercise we need to bring SystemTime
and UNIX_EPOCH
into main scope.
We can do this by using use
like below: