美文网首页
Rust 编程语言-7-packages,crates,modu

Rust 编程语言-7-packages,crates,modu

作者: onemoremile | 来源:发表于2022-01-10 19:18 被阅读0次

    package

    • src/main.rs 是crate的默认约定入口, 或者src/lib.rs
    • 一个package由一个或多个crate组成
    • 二进制程序,或者lib 库
    $ cargo new my-project
         Created binary (application) `my-project` package
    $ ls my-project
    Cargo.toml
    src
    $ ls my-project/src
    main.rs
    

    modules

    mod front_of_house {
        mod hosting {
            fn add_to_waitlist() {}
    
            fn seat_at_table() {}
        }
    
        mod serving {
            fn take_order() {}
    
            fn serve_order() {}
    
            fn take_payment() {}
        }
    }
    

    mod的例子

    mod front_of_house {
        mod hosting {
            fn add_to_waitlist() {}
    
            fn seat_at_table() {}
        }
    
        mod serving {
            fn take_order() {}
    
            fn serve_order() {}
    
            fn take_payment() {}
        }
    }
    
    • use
      引入外部库/系统库到当前crate
    • pub
      让当前module、方法对外可见

    相关文章

      网友评论

          本文标题:Rust 编程语言-7-packages,crates,modu

          本文链接:https://www.haomeiwen.com/subject/qxakcrtx.html