tezvyn:

Structural Go interfaces versus nominal Rust traits

Source: interviewintermediate

WHAT IT TESTS: grasp of typing models and their design impact. OUTLINE: Go interfaces are satisfied implicitly by method shape (structural); Rust traits must be explicitly implemented (nominal).

WHAT IT TESTS: whether you understand structural versus nominal conformance and its practical consequences. ANSWER OUTLINE: Go's io.Reader is satisfied by any type with a matching Read method, with no declaration of intent, so types from unrelated packages conform automatically; great for decoupling and easy test doubles. Rust's Read trait must be explicitly implemented, making conformance intentional and discoverable, and enabling the orphan-rule guarantees, but you cannot retrofit a foreign trait onto a foreign type without a newtype.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Structural Go interfaces versus nominal Rust traits · Tezvyn