< 返回版块

苦瓜小仔 发表于 2025-07-16 11:50

Tags:日报

Rust 官方:从 1.90 开始 LLD 成为 x64 Linux 上的默认链接器

PR:https://github.com/rust-lang/rust/pull/140525

文章《在 reqwest 库中添加重试功能》

作者:Sean McArthur

这篇文章介绍了 reqwest 库中添加重试 (retries) 功能的设计思路和实现细节。

作者指出,间歇性失败是网络请求中常见的问题,而简单的重试机制可以显著改善这种情况。

文章提出了一个灵活的重试策略,包括默认启用预算限制(避免过度重试)、基于作用域的重试(区分不同目标)以及请求克隆(在 Rust 的所有权模型下实现请求的重复使用)。

此外,还讨论了如何通过分类器(classifiers)自定义重试条件,以及未来可能的增强功能,如指数退避(backoffs)和可重放的请求体(replayable body)。

作者希望通过这些设计,让用户能够更方便地在 reqwest 中使用重试功能,并计划将一些通用的设计思路推广到 towertower-http 中。

目前,相关功能正在通过一个拉取请求实现,作者欢迎社区的反馈和试用。

阅读:https://seanmonstar.com/blog/reqwest-retries/

Reddit:https://www.reddit.com/r/rust/comments/1m0jrv0/exploring_easier_http_retries_in_reqwest/

文章《向 Regex 库添加 lookbehinds 功能》

作者:Systems and Formalisms Lab

这篇文章介绍了如何在 Rust 的线性时间正则表达式引擎中添加无捕获组的回溯(lookbehinds)功能。

回溯允许正则表达式在不将匹配内容视为最终结果的情况下,对模式前的内容进行断言。

文章详细描述了实现过程,包括对 Rust 正则表达式引擎架构的分析、对前端解析器和后端引擎的修改,以及如何解决性能问题。

此外,还介绍了如何优化有界回溯的性能,并尝试在回溯引擎中实现回溯支持。

最终,通过基准测试验证了实现的正确性和性能合理性,证明了该功能在 Rust 生态系统中的实用性。

阅读:https://systemf.epfl.ch/blog/rust-regex-lookbehinds/

Reddit:https://www.reddit.com/r/rust/comments/1m0l88r/adding_lookbehinds_to_rustlangregex_systemf_epfl/

Bitpiece:定义和操作位字段的库

bitpiece 是一个 Rust crate,用于定义和操作位字段的库,通过过程宏简化了位级数据操作。

它允许开发者使用简单的 Rust 结构体和枚举定义复杂的位字段布局,并自动生成类型安全的 API 用于交互。

主要特性包括:

  • 声明式定义:使用简单结构体和枚举定义位字段。
  • 类型安全:自动生成字段的 getter 和 setter,避免手动位移和掩码操作。
  • 灵活性:支持非标准位长度的类型(如 6 位结构体)。
  • 嵌套支持:可以将 bitpiece 类型嵌套在其他类型中。
  • 任意宽度整数:提供 B1-B64SB1-SB64 类型用于非标准位宽的无符号和有符号整数。
  • 编译时验证:可指定结构体的预期位长度,确保编译时匹配。
  • 安全与非安全 API:提供 from_bitstry_from_bits 方法,分别用于可能失败的位字段创建。
  • 兼容性:支持 #![no_std]

bitpiece 特别适合处理网络协议、硬件接口或任何需要数据紧凑化的场景。它通过强大的过程宏和灵活的 API,让位字段操作变得简单而安全。

仓库:https://github.com/roeeshoshani/bitpiece

Reddit:https://www.reddit.com/r/rust/comments/1lwrc8h/bitpiece_bitfields_in_rust_made_easy/

// Define a 2-bit enum for the packet's priority.
// The macro automatically infers it needs 2 bits.
#[bitpiece]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Priority {
    Low = 0,
    Medium = 1,
    High = 2,
    Critical = 3,
}

// Define the packet header structure.
// The macro calculates the total size (1 + 2 + 5 = 8 bits).
#[bitpiece(8)] // The `(8)` is optional but validates the size at compile time.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct PacketHeader {
    is_fragment: bool,
    priority: Priority,
    payload_len: B5, // A 5-bit integer type
}

fn main() {
    // Create a new header from raw bits (e.g., received from a network).
    // Bits: 0b101_10_1 => is_fragment=1, priority=2 (High), payload_len=5
    let mut header = PacketHeader::from_bits(0b101101);

    // Use the generated getter methods to safely access fields.
    assert_eq!(header.is_fragment(), true);
    assert_eq!(header.priority(), Priority::High);
    assert_eq!(header.payload_len().get(), 5); // Use .get() for B-types

    // Use the generated setter methods to modify the header.
    header.set_priority(Priority::Critical);
    header.set_payload_len(B5::new(31)); // Set to max value (2^5 - 1)

    assert_eq!(header.priority(), Priority::Critical);
    assert_eq!(header.payload_len().get(), 31);

    // The underlying storage is automatically updated.
    // Bits: 0b11111_11_1
    assert_eq!(header.to_bits(), 0b11111111);

    // You can also construct a bitpiece from its fields directly.
    let from_fields = PacketHeader::from_fields(PacketHeaderFields {
        is_fragment: false,
        priority: Priority::Low,
        payload_len: B5::new(10),
    });

    assert_eq!(from_fields.to_bits(), 0b1010000);
}

Rwatch:watch 命令的 Rust 替代

rwatch 是一个现代化的跨平台 Rust 替代品,用于替代传统的 watch 命令。

它支持周期性运行命令并全屏显示输出,能够高亮显示运行之间的差异(通过 -d/--differences 选项),支持 ANSI 颜色输出(通过 -c/--color 选项),还可以在命令失败时发出提示音(通过 -b/--beep 选项)。

此外,它还支持自定义更新间隔、无标题模式、无换行模式和直接执行模式等。

仓库:https://github.com/davidhfrankelcodes/rwatch

Reddit:https://www.reddit.com/r/rust/comments/1lwvbxf/i_rewrote_the_watch_command_in_rust/

--

From 日报小组 苦瓜小仔

社区学习交流平台订阅:

评论区

写评论

还没有评论

1 共 0 条评论, 1 页