tezvyn:

Go & Rust

Go web services, Rust backends, systems programming

276 bites

Go & Rust84 sec read

Associated types vs generic type parameters in traits

WHAT IT TESTS: trait design and type-level reasoning. OUTLINE: associated types fix one type per implementer; generics allow many impls; Iterator::Item is the canonical example. RED FLAG: claiming they are interchangeable or that generics are always better.

Go & Rust87 sec read

Value versus pointer receivers and interface satisfaction

WHAT IT TESTS: method sets and interface satisfaction. OUTLINE: value-receiver methods belong to both T and *T, but pointer-receiver methods belong only to *T, so a value of T may not satisfy an interface.

Go & Rust2 min read

When to panic in Go versus Rust

WHAT IT TESTS: error philosophy and panic boundaries. OUTLINE: both reserve panic for unrecoverable bugs and use values, Result or error, for expected failures; Rust's type system pushes more cases to Result.

Go & Rust2 min read

Rust borrow rules versus Go race prevention

WHAT IT TESTS: how each language stops data races. OUTLINE: Rust's aliasing-XOR-mutability rule plus Send and Sync make races a compile error; Go prevents them at runtime via channels, mutexes and the race detector.

Go & Rust87 sec read

Rust workspace versus single crate for plugins

WHAT IT TESTS: structuring a modular Rust system. OUTLINE: a workspace gives incremental compilation, enforced API boundaries via a shared api crate, and per-plugin deps; a single crate is simpler but recompiles wholesale and blurs boundaries.

Go & Rust84 sec read

Rust binary and library crates in one project

WHAT IT TESTS: crate structure and code reuse. OUTLINE: a binary crate has main and produces an executable; a library crate has lib.rs and is reusable; put logic in the lib and a thin main that calls it. RED FLAG: duplicating core logic inside main.rs.

Go & Rust83 sec read

Refactoring under Go simplicity versus Rust correctness

WHAT IT TESTS: how language philosophy shapes refactors. OUTLINE: Rust's type system catches broken invariants at compile time so refactors are guided; Go's explicitness keeps code readable but shifts safety to tests and discipline.

Go & Rust86 sec read

I/O Stream Abstractions

I/O stream abstractions like Go's io.Reader and io.Writer model data as a flow of bytes behind a tiny interface, so files, sockets, buffers and encoders compose interchangeably without each one knowing the others' concrete type.

Go & Rust87 sec read

Implicit Interface Satisfaction in Go

Go types satisfy an interface automatically by having the right methods, with no explicit implements declaration. This structural typing decouples implementations from interface definitions, so you can define interfaces around how you use a type without…

Explain the performance overhead of a cgo call
Go & Rust2 min read

Explain the performance overhead of a cgo call

Tests cgo transition penalties and scheduler semantics. A strong answer cites the ~100x overhead (~171ns vs ~1.8ns), notes C blocks an OS thread and starves the scheduler, and warns about memory copy taxes. Red flag: claiming cgo is free or ignoring blocking.

Go & Rust2 min read

Why must FFI-bound structs use #[repr(C)] and what breaks without it?

WHAT IT TESTS: Rust ABI stability across FFI. ANSWER OUTLINE: repr(C) fixes field order, size, alignment to C rules for extern calls; omitting it lets Rust reorder or pad fields, causing UB. RED FLAG: Believing default layout is stable or repr(C) is optional.

Use a C malloc'd char* in Go and Rust, then free it
Go & Rust2 min read

Use a C malloc'd char* in Go and Rust, then free it

Tests FFI allocator discipline. In Go, copy with C.GoString then C.free the *C.char. In Rust, read via CStr::from_ptr, copy to String, then libc::free. Red flag: letting Go GC or Rust Drop manage C memory, or using CString::from_raw on C malloc'd pointers.

Go & Rust2 min read

Pass a string from Go and Rust to C safely

This tests FFI ownership and null-termination. In Go, use C.CString then C.free it. In Rust, create a std::ffi::CString, bind it to a let, then pass as_ptr while the binding lives. Red flag: claiming Rust is auto-safe without mentioning the temp-drop gotcha.

Go & Rust2 min read

Purpose of Go import C and Rust equivalent mechanism

This tests FFI entry points: Go's import "C" activates cgo to reference C symbols directly, while Rust uses an unsafe extern "C" block to declare external functions. A red flag is calling either a normal import or omitting unsafe in Rust.

Go & Rust2 min read

Design a safe Rust wrapper taking &[i32] and returning Vec<i32>

Tests Rust FFI buffer-output encapsulation. A strong answer declares an unsafe extern C block, allocates a Vec with capacity, passes as_mut_ptr and a local size_t, validates returned length, then calls set_len.

Go & Rust2 min read

Implement a custom derive macro for a Builder pattern

Tests proc-macro AST transformation. A strong answer lists: parse TokenStream with syn into DeriveInput, inspect fields, then quote builder code as TokenStream, noting the separate proc-macro crate. Red flag: treating tokens as strings instead of AST nodes.

Go & Rust2 min read

What are Rust's three procedural macros and derive's advantage over macro_rules?

Tests Rust macros and AST generation vs text macros. Lists derive, attribute-like, and function-like macros, then explains derive needs AST introspection for per-field impl unreachable with macro_rules. Red flag: that macro_rules can iterate struct fields.

Go & Rust2 min read

In Go's reflect package, what is settability and how is it obtained?

This tests whether you know reflection mutates only addressable storage. Settability means a Value points to actual memory; obtain it by calling reflect.ValueOf on a pointer then Elem, or on slice elements. Set panics when the Value is a copy, not an address.

Go & Rust2 min read

Using reflect, iterate a pointer-to-struct's fields

Tests fluency with Go reflection for indirection and field traversal. Outline: ValueOf/TypeOf, guard IsValid, check Kind==Ptr, Elem to struct, loop NumField with Type for names and Value for values. Red flag: Field() on the pointer before Elem panics.

Go & Rust2 min read

What does unsafe enable in Go and Rust? List two operations.

WHAT IT TESTS: Your grasp of where each language drops memory-safety guarantees. ANSWER OUTLINE: Go unsafe enables pointer arithmetic and type punning; Rust unsafe permits raw pointer dereferencing and FFI.