Rust constants in different modules? -
i have "main.rs" file declare version constant.
pub const version: &'static str = "v2"; mod game; fn main() { do_stuff(); }
then want access global constant in different module "game.rs":
pub fn do_stuff() { println!("this version: {}", version); }
how make constant available everywhere?
as version
declared in main.rs
, crate root, can access using absolute path: ::version
.
this should work:
pub fn do_stuff() { println!("this version: {}", ::version); }
Comments
Post a Comment