Windows安装踩坑
- 如果是Windows系统可以看这篇文章,作者写的挺详细的。但是也遇到了一些问题,记录如下:
- cargo run 报错
error: linker link.exe not found | = note: program not found
,下载Microsoft C++ 生成工具
- 有些依赖可能需要cmake,直接去https://cmake.org/download/下载安装即可,直接下一步就行,安装包会自动设置环境变量
VSCODE Rust插件
- 感觉这个rust-analyzer插件挺好用的。
调试插件
试用
-
比如代码
use libp2p::{identity, ping, Multiaddr, PeerId};
+let behaviour = ping::Behaviour::new(ping::Config::new().with_keep_alive(true));
中的ping::Config::new().with_keep_alive(true)
部分。 -
use libp2p::{identity, ping, Multiaddr, PeerId};
这句的结构为use crate::module::submodule;
, -
crate(箱子)是 Rust 项目的一个编译单元。一个 crate 可以是一个库(library crate),也可以是一个可执行文件(binary crate)。每个 crate 都有一个唯一的名称,
并形成一个单独的命名空间
。 -
ping::Config::new().with_keep_alive(true)
中ping是module
,Config
是带有函数的结构体(C语言结构体里不能有函数,所以可以说是C++中的结构体(或类)一样)。
impl Config {
……
/// 构造函数
pub fn new() -> Self {
Self {
timeout: Duration::from_secs(20),
interval: Duration::from_secs(15),
max_failures: NonZeroU32::new(1).expect("1 != 0"),
keep_alive: false,
}
}
}
……
/// 设置是否通过 ping 协议本身来保持连接处于活动状态,而不考虑最大允许的失败次数。
/// Sets whether the ping protocol itself should keep the connection alive,
/// apart from the maximum allowed failures.
///
/// By default, the ping protocol itself allows the connection to be closed
/// at any time, i.e. in the absence of ping failures the connection lifetime
/// is determined by other protocol handlers.
///
/// If the maximum number of allowed ping failures is reached, the
/// connection is always terminated as a result of [`ConnectionHandler::poll`]
/// returning an error, regardless of the keep-alive setting.
pub fn with_keep_alive(mut self, b: bool) -> Self {
self.keep_alive = b;
self
}
- 可在右侧观察变量数值,切换CALL STACK 查看调用过程