Rust: function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
 * file: nested.rs
 * IDE: vscode
 *
 */
 
///公有函数
pub fn function() {
    println!("called `my::nested::function()`");
}
 
///私有函数
#[allow(dead_code)]
fn private_function() {
    println!("called `my::nested::private_function()`");
}

  

1
2
3
4
5
6
7
8
9
10
/**
 * file inaccessibler.rs
 * https://code.visualstudio.com/docs/languages/rust
 */
 
///公有函数
#[allow(dead_code)]
pub fn public_function() {
    println!("called `my::inaccessible::public_function()`");
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
 * 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();
}

  

 

 

调用:

1
2
3
4
5
6
7
mymod::function();
//windows_gui::GuiFactory();
 
my::function();
my::indirect_access();   
my::nested::function();
let windows = true;

  

 

 Code Runner 安装插件,代码一键运行

posted @   ®Geovin Du Dream Park™  阅读(6)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2022-10-19 Python: Bridge Pattern
2022-10-19 Python: Builder Pattern
2011-10-19 Csharp windowform controls clear
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示