Compare `protocol` with Go interfaces, Swift existentials and Rust trait objects
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 71/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- documentation
Hướng nghiên cứu
Đọc OUTLINE.md §3 và dùng phần so sánh trong issue để viết mỗi nội dung một câu về interface của Go, existential của Swift và trait object của Rust. Khi cần, hãy kiểm tra độ chính xác của các tài liệu tham khảo được liên kết. Hoàn tất khi §3 có đủ ba câu được yêu cầu, dựa trên phần so sánh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- C++
- Star
- 12
- Fork
- 4
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 21
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của jbcoe/cc-protocol
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
jbcoe/cc-protocol#507 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
jbcoe/cc-protocol#455 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
jbcoe/cc-protocol#407 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
jbcoe/cc-protocol#194 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
jbcoe/cc-protocol#519 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của jbcoe/cc-protocol
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[SDL3pp] update to 0.12.0Đang mởcategory:port-update
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
bug-unconfirmed
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue help wanted phase:0 priority:P3 type:task
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày