テーマ: rust
-
新しいサービスにGoとRustのどちらを選ぶか:ベンチマークなしの判断手順
ベンチマークの俗説ではなく、文書化された言語の性質とチームの制約からGoかRustを選びます。メモリー管理モデル、エラーと並行処理のスタイル、負荷の形、必要な連携ライブラリ、そして2年後に誰が保守するかを見ます。
-
Rust のパックされたフィールド:生ポインターへのキャスト前に非整列参照を作らない
一時的な参照でも既にアラインメント要件に違反し得る理由を理解し、可能なら明示的なバイトデコードを優先する。
-
Rust Pin:ポインター変数を固定せず、参照先のアドレスを保つ
アドレスに依存する値と、それを移動し得る操作を特定して、ピン留めのエラーを診断します。
-
Cargo、クレート、エディション:Rust プロジェクトのビルドとバージョン管理
Cargo は Cargo.toml からクレートをビルドし、SemVer 互換範囲の依存関係を解決して Cargo.lock に記録します。一つのビルドに同じクレートの互換性のない二つのメジャーバージョンを含められます。エディションはクレートごとに任意で選ぶ相互運用可能な言語バージョンなので、変更しても依存する側に追従を強制しません。
-
FFI 境界の CString:借用ポインターと所有権の移転を区別する
借用する呼び出しでは CString の所有者を生存させ、所有権を raw 形式へ変換するのは明示的な返却契約がある場合に限ります。
-
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 をまたいで保持する状態を調べる
unsafe なトレイト実装を追加せず、中断をまたいで何が残るかを調べ、spawn する future を修正します。
-
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 のスタック巻き戻し:パニックと例外の境界を明示的に選ぶ
境界の ABI を選ぶ前に、通常のエラー戻り値、Rust のパニック、外部言語の例外を分けて考える。
-
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