Rust学习笔记:Windows安装记录+Rust插件与Rust代码调试

Windows安装踩坑

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 有些依赖可能需要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是moduleConfig是带有函数的结构体(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 查看调用过程
    在这里插入图片描述
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值