/** * file: nested.rs * * */ ///公有函数 pub fn function() { println!("called `my::nested::function()`"); } ///私有函数 #[allow(dead_code)] fn private_function() { println!("called `my::nested::private_function()`"); }
/** * file inaccessibler.rs * https://code.visualstudio.com/docs/languages/rust */ ///公有函数 #[allow(dead_code)] pub fn public_function() { println!("called `my::inaccessible::public_function()`"); }
/** * file: my.rs * * * */ mod inaccessible; //从文件 inaccessible.rs pub mod nested; //从文件 nested.rs ///公有函数 pub fn function() { println!("called `my::function()`"); } ///私用函数 fn private_function() { println!("called `my::private_function()`"); } ///公有函数 pub fn indirect_access() { print!("called `my::indirect_access()`, that\n> "); private_function(); }
调用:
mymod::function(); //windows_gui::GuiFactory(); my::function(); my::indirect_access(); my::nested::function(); let windows = true;
Code Runner 安装插件,代码一键运行
标签:function,rs,nested,Rust,my,called,fn From: https://www.cnblogs.com/geovindu/p/17773881.html