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

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -