Compare `protocol` with Go interfaces, Swift existentials and Rust trait objects
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 71/100
- Tipo di issue
- Documentazione
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- documentation
Direzione di ricerca
Leggi OUTLINE.md §3 e usa il confronto nell’issue per scrivere una frase ciascuno sulle interfacce di Go, gli esistenziali di Swift e gli oggetti trait di Rust. Se necessario, verifica l’accuratezza dei riferimenti collegati. Il lavoro è terminato quando §3 contiene le tre frasi richieste, basate sul confronto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- C++
- Stelle
- 12
- Fork
- 4
- Merge medio
- 1g 23h
- PR unite (30g)
- 21
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di jbcoe/cc-protocol
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
jbcoe/cc-protocol#507 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
jbcoe/cc-protocol#455 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
jbcoe/cc-protocol#407 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
jbcoe/cc-protocol#194 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
jbcoe/cc-protocol#519 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di jbcoe/cc-protocol
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 1 giorno
-
[SDL3pp] update to 0.12.0Apertacategory:port-update
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni
-
bug-unconfirmed
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
good first issue help wanted phase:0 priority:P3 type:task
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno