Rust: function

/**
 * 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()`");
}

  

/**
 * 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 安装插件,代码一键运行

posted @ 2023-10-19 08:53  ®Geovin Du Dream Park™  阅读(6)  评论(0编辑  收藏  举报