主题: rust
-
为新服务选择 Go 或 Rust:不使用基准测试的决策流程
根据有文档依据的语言属性和团队约束,在 Go 与 Rust 之间作出选择,而不是听信基准测试传闻:内存管理模型、错误与并发风格、工作负载形态、服务必须对接的库,以及两年后由谁维护。
-
Rust 的 packed 字段:转换为裸指针前,避免创建未对齐引用
理解为什么临时引用也可能已经违反对齐要求,并尽可能优先采用显式字节解码。
-
Rust Pin:保持所指对象的地址,而不是固定指针变量
确定依赖地址稳定的值及可能移动它的操作,以诊断固定错误。
-
Cargo、crate 与 edition:Rust 项目的构建和版本管理
Cargo 根据 Cargo.toml 构建 crate,将 SemVer 兼容范围内的依赖解析到 Cargo.lock,并能在一次构建中包含同一 crate 的两个不兼容主版本。Edition 是每个 crate 自行选择、可互操作的语言版本,因此升级某个 crate 的 edition 不会迫使依赖它的 crate 一同升级。
-
FFI 边界上的 CString:区分借用指针与转移所有权
在借用调用期间保持 CString 所有者存活,仅在有明确归还契约时使用原始所有权转换。
-
Rust 所有权与借用概览
每个 Rust 值恰好有一个所有者,所有者离开作用域时该值被释放;传递值会移动它,除非其类型实现 Copy。引用借用值时遵循同一时刻只能有一个可变引用或任意多个共享引用的规则。借用检查器在编译时强制执行这些规则,从而在无需垃圾回收器的情况下保证内存安全。
-
Rust FFI 布局:外层结构体的 repr(C) 不会修复嵌套字段
审查跨越 C ABI 边界的每个字段,并在每个受支持的目标平台上验证布局。
-
Rust FFI 资源所有权:将外部构造函数与实际对应的析构函数配对
在围绕外部资源构建的窄接口 Rust 包装器中,明确分配、释放和回调生命周期。
-
How much longer does it take an engineer from a dynamic language to become productive in Rust than in Go, and which concepts account for the gap?
Open question: Go is often described as quick to pick up and Rust as demanding, and the 2024 State of Rust survey reports that around 31% of non-users cite perceived difficulty; but few sources measure time to a first merged change, time to unsupervised code review, or which concepts (ownership, lifetimes, async, traits) consume that time for engineers arriving from Python, Ruby or JavaScript.
-
Tokio 的 Send 错误:检查跨越 await 保留的状态
检查哪些状态在挂起后仍然存在,以修复经 spawn 启动的 future,而不是添加 unsafe trait 实现。
-
Rust traits versus Go interfaces: explicit impl, implicit satisfaction
Both languages abstract over behaviour without class hierarchies, but a Go type satisfies an interface by merely having the methods, while a Rust type implements a trait only through an explicit impl block subject to the orphan rule; Rust additionally separates compile-time generics (monomorphised) from dyn trait objects (dynamic dispatch), a choice Go makes for the programmer.
-
Result, Option and the ? operator: error handling in Rust
Rust has no exceptions and no null: fallible operations return Result<T, E>, absent values are Option<T>, and both are enums the compiler makes you match. The ? operator returns Err or None early and converts error types through From, and an ignored Result triggers a compiler warning because the type is marked #[must_use].
-
Rust FFI 栈展开:明确选择 panic 与异常的边界
选择边界 ABI 之前,先区分普通错误返回、Rust panic 和外部异常。
-
For engineers new to Rust, build wait time overtakes borrow-checker errors as the main logged friction within the first two months
Hypothesis: borrow-checker errors dominate the friction that engineers new to Rust record in their first weeks, but their share falls quickly, while entries about waiting for builds (despite cargo check, which the Cargo documentation describes as skipping code generation and therefore being faster than cargo build) rise and become the largest category within two months; a proposed friction-log test, with no result claimed.
机器可读: JSON