Obs: cuando se habla de “declare a module” se hace referencia a importarlo o bien definirlo ahí mismo.
mod garden;. The compiler will look for the module’s code in these places:
mod garden (lo defino ahi)mod vegetables; in src/garden.rs. The compiler will look for the submodule’s code within the directory named for the parent module in these places:
mod vegetables, within curly brackets instead of the semicolonAsparagus type in the garden vegetables module would be found at crate::garden::vegetables::Asparagus.use keyword: Within a scope, the use keyword creates shortcuts to items to reduce repetition of long paths. In any scope that can refer to crate::garden::vegetables::Asparagus, you can create a shortcut with use crate::garden::vegetables::Asparagus; and from then on, you only need to write Asparagus to make use of that type in the scope.usualmente en
lib.rs
solo se declaran los módulos, en sus archivos particulares estaran las funciones o estructuras asociadas a ese modulo.
Por ejemplo, podrías tener un
lib.rs
con el siguiente aspecto:
//! src/lib.rs
mod adder;
mod multiplier;