码迷,mamicode.com
首页 > 其他好文 > 详细

Rust中的Cargo工作空间实践

时间:2019-08-31 19:27:37      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:pac   mod   init   png   pre   reference   end   dde   inf   

这是为了开发大型程序,分治crate用的。

目录结构如下:

 技术图片

一,根cargo.toml内容

[workspace]

members = [
    "adder",
    "add-one",
    
]

二,adder里的cargo.toml内容

[package]
name = "adder"
version = "0.1.0"
authors = ["test <test@qq.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
add-one = { path = "../add-one" }

三,main.rs内容

use add_one;

fn main() {
    let num = 10; 
    println!("Hello, world! {} plus one is {}!", num, add_one::add_one(num));
}

四,Lib.rs内容

pub fn add_one(x: i32) -> i32 {
    x + 1
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        assert_eq!(3, add_one(2));
    }
}

 

Rust中的Cargo工作空间实践

标签:pac   mod   init   png   pre   reference   end   dde   inf   

原文地址:https://www.cnblogs.com/aguncn/p/11439898.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!