Compare `protocol` with Go interfaces, Swift existentials and Rust trait objects
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 71/100
- issue の種類
- ドキュメント
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
調査の方向性
OUTLINE.md §3を読み、issue内の比較を使って、Goのインターフェース、Swiftのexistential、Rustのtrait objectについてそれぞれ1文ずつ書いてください。必要に応じて、リンクされた参考資料の正確さを確認してください。§3に比較に基づく指定の3文が含まれたら完了です。
索引モデルが issue の本文から書いたものです。
説明
OUTLINE.md §3 asks for a sentence each on Go, Swift and Rust. This is the comparison behind those sentences. Thanks to Valentyn Yukhymenko for the Go references.
protocol |
Go interface | Swift any P |
Rust dyn Trait |
|
|---|---|---|---|---|
| Conformance | Structural, exact signatures | Structural, exact signatures | Declared: extension T: P |
Declared: impl Trait for T |
| Checked | Compile time | Compile time from a concrete type; run time between interfaces | Compile time; run time for as? any P |
Compile time |
| Representation | protocol_view: vtable pointer and object pointer. protocol: vtable pointer, storage with a small buffer, allocator |
itab pointer and data pointer | Three-word buffer or heap box, type metadata pointer, one witness table pointer per protocol | Data pointer and vtable pointer |
| Ownership | protocol owns and deep-copies; protocol_view borrows |
Garbage collected | Value semantics | Chosen by the pointer: Box, &, Rc |
| Copy and destroy | Owning vtable | Not needed | Value witness table, reached from the type metadata | Drop in the vtable; no copy |
| Table built | Compile time, per interface and type | Compile time from a concrete type; run time between interfaces, cached in a global hash table | Compile time, per conformance | Compile time, per trait and type |
| Type identity | const std::type_info* in the vtable |
Type descriptor in the itab, which reflect reads |
Type metadata pointer | None in the vtable |
| Composition | None (#511) | Embedded interfaces | P & Q |
Supertraits; dyn A + B is not allowed |
| Narrowing | None (#98) | To any subset interface, at run time | From P & Q to P |
To a supertrait, since Rust 1.86 |
| Erased type satisfies its own interface | No (#262) | Interface values convert without nesting | No | Yes |
| Members from a base or embedded type count | No (#513) | Yes | n/a | n/a |
| Default implementations | None (#510) | None | Protocol extensions | Bodies in the trait |
| Comparing two erased values | None (#440) | == compares dynamic types then values; panics if the type is not comparable |
Not built in | Not built in |
| Empty state | Valueless after move | nil |
None | None |
Go is the closest: implicit conformance, exact signatures, and the same two words in a view. It differs where it relies on a runtime: garbage collection instead of ownership, no small buffer, and tables built at run time. Swift is the closest on storage, with an inline buffer and per-type copy and destroy operations. Rust is closer to proxy than to protocol, since the pointer decides ownership.
Follow-ups: guardrails against accidental conformance (#518), a type descriptor for run-time metadata (#519), and comments on #513, #511, #98, #262 and #121.
References:
- Russ Cox, Go Data Structures: Interfaces
- Rob Pike, Go at Google; Go FAQ;
runtime/iface.go - Swift TypeLayout, SE-0352, SE-0364
- Rust Reference: trait objects, orphan rules
- 主要言語
- C++
- スター
- 12
- フォーク
- 4
- 平均マージ
- 1日 23時間
- マージ済み PR(30日)
- 21
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
jbcoe/cc-protocol のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
jbcoe/cc-protocol#507 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
jbcoe/cc-protocol#455 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
jbcoe/cc-protocol#407 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
jbcoe/cc-protocol#194 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
jbcoe/cc-protocol#519 ·
メンテナーはふだん 1 日以内に返信
jbcoe/cc-protocol の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
メンテナーはふだん 1 日以内に返信
-
category:port-update
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
bug-unconfirmed
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
good first issue help wanted phase:0 priority:P3 type:task
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信