环境

  • Rust 1.56.1
  • VSCode 1.61.2

概念

参考:https://doc.rust-lang.org/stable/rust-by-example/testing/dev_dependencies.html

示例

main.rs

#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;

pub fn add(a: i32, b: i32) -> i32 {
    a + b
}

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

    #[test]
    fn test_add() {
        assert_eq!(add(2, 3), 5);
    }
}

fn main(){
    
}

Cargo.toml

[package]
name = "rust"
version = "0.1.0"
edition = "2021"

[dependencies]

[dev-dependencies]
pretty_assertions = "0.4.0"

总结

了解了 Rust 中开发依赖的使用方式。

附录

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-18
  • 2021-07-31
  • 2021-07-30
  • 2021-08-22
  • 2021-08-06
猜你喜欢
  • 2021-10-19
  • 2023-02-20
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
相关资源
相似解决方案