Skip to content
tezvyn:

Rust

190 bites tagged Rust — interview questions with model answers, and 60-second explainers.

Go & Rust2 min read

Why are Rust's borrowing rules stricter than Go's pointers?

This tests compile-time versus runtime safety tradeoffs. A strong answer contrasts Go's aliasing with Rust's rule of one mutable or many immutable references to prevent data races without a GC. A red flag is calling Rust strict without citing race prevention.

Go & Rust2 min read

Explain Rust's Ownership and its three compiler-enforced rules

Tests your grasp of Rust's compile-time memory model. A strong answer lists the three ownership rules, links them to stack versus heap, and notes borrow checking enforces them at compile time. Red flag: calling it manual memory management.

Go & Rust2 min read

Explain the difference between mod and use in Rust

Mod tells the compiler to compile a file into the crate tree; use brings an existing path into scope as a shortcut. declaration versus import in Rust's module system.

Go & Rust2 min read

How do Go and Rust control visibility of functions and types?

Tests encapsulation conventions in systems languages. Go uses capitalization: uppercase exports across packages; Rust uses explicit pub keywords with module-level privacy. Red flag: claiming either uses Java-style access modifiers or runtime visibility.

Go & Rust3 min read

Compare enum vs trait objects for heterogeneous shapes in Rust

This tests compile-time vs run-time polymorphism in Rust. A strong answer contrasts enum's closed set, static dispatch, and stack layout against trait objects' open extensibility, heap allocation, and vtable indirection.

Go & Rust2 min read

How does struct field ordering affect memory layout in Go and Rust?

It tests alignment, padding, and compiler layout knowledge. A strong answer explains that alignment inserts padding, Go and Rust keep declared order, and reordering by size can shrink size. Red flag: saying order is irrelevant or that compiler auto-packs.

Go & Rust2 min read

Sum Some values in Vec<Option<i32>>, ignoring None

Tests Rust Option handling and null-safety design. A strong answer uses map, unwrap_or, flatten, or match to skip Nones safely, and explains Option replaces null pointers with explicit enum variants. Red flag: using unwrap in a loop or suggesting null checks.

Go & Rust2 min read

What type replaces String for read-only function parameters in Rust?

Use &str; it borrows without ownership, accepts literals and String via coercion, and avoids clones. Knowledge of Rust's read-only string view and API ergonomics.

Go & Rust2 min read

Define a WebEvent enum with PageLoad, PageUnload, and KeyPress

Tests Rust enum syntax: unit versus tuple variants. A good answer defines WebEvent with PageLoad, PageUnload, and KeyPress(char), then instantiates WebEvent::KeyPress('q'). A red flag is forgetting the double colon or using struct variant syntax.

Go & Rust2 min read

Shadowing in Go and Rust: idioms, bugs, and if-block scoping

Tests lexical scoping in Go and Rust. Strong answers show Go's := narrowing and Rust's let rebinding, warn that Go's if := scopes across both branches, and contrast that with Rust's block-local let. Red flag: calling shadowing mutation.

Go & Rust2 min read

Go nil pointers vs Rust Option: impact on signatures and safety

Tests encoding of absence. Go nil means any pointer may be null, pushing checks to runtime; Rust Option<T> forces compile-time handling. Strong answers cover signatures, validity, and NPO. Red flag: calling Option syntactic sugar for null.

Go & Rust2 min read

Default integer overflow behavior in Go versus Rust

Go wraps silently; Rust panics in debug, wraps in release; Rust has wrapping_, checked_, saturating_ methods; Go needs manual checks. Go silent wrapping vs Rust mode-based defaults. Saying Go panics or Rust never wraps.

Go & Rust2 min read

Describe Go slice internals and compare to Rust slice and Vec

Go slices are three-word headers over an array; Rust &[T] is a two-word borrow without capacity; Vec<T> is an owned buffer that reallocates. Memory layout and ownership of buffers.

Go & Rust2 min read

Parse a string to integer in Go and Rust with errors

This tests whether you map each language's error philosophy to syntax. Outline: Go returns (int, error) and callers check err != nil; Rust returns Result<i32, E> and callers match Ok/Err. Red flag: suggesting exceptions or ignoring Rust's must-use Result.

Go & Rust2 min read

Compare Go string and Rust &str/String types, mutability, UTF-8, ownership

This tests your model of immutable UTF-8 strings versus owned buffers. A strong answer contrasts Go's read-only header with Rust's &str borrow and heap-owned String, noting Go immutability is structural while Rust gates mutation via ownership.

Go & Rust2 min read

Compare Go's switch with Rust's match on exhaustiveness, fallthrough, and expressions.

Tests grasp of expression vs statement semantics and type safety. Go switch auto-breaks and lacks exhaustiveness; Rust match requires exhaustive patterns, forbids fallthrough, and yields values. Never say Go switch returns a value or Rust match falls through.

Go & Rust2 min read

Write a 1-to-5 loop in Go and Rust

Write Go's three-clause for, write Rust's 1..=5 range iterator, and contrast statement iteration with iterator consumption. idiomatic loop syntax in Go versus Rust.

Go & Rust2 min read

How does Go's variable declaration and mutability differ from Rust?

Contrast Rust let (immutable) and let mut (mutable) with Go var and := (mutable), noting Go uses const for immutability. Mutability defaults and syntax. Claiming Go variables are immutable or that := behaves like const.

Go & Rust2 min read

Contrast unsafe in Go versus Rust and the invariants you assume

Tests divergent safety philosophies. Go unsafe enables FFI and pointer casting; you guarantee valid memory, alignment, and GC reachability. Rust unsafe unlocks raw pointers and FFI; you manually uphold aliasing and validity invariants behind safe APIs.

Go & Rust2 min read

Compare Go interfaces with Rust traits

This tests structural versus nominal polymorphism and API design. A strong answer contrasts Go's implicit satisfaction with Rust's explicit impl and dyn Trait. Red flag: calling one universally better without discussing coupling or backwards compatibility.

Go & Rust2 min read

Compare Go's GC and Rust's ownership across performance, productivity, and safety

This tests memory-model trade-offs. Contrast Rust's compile-time ownership for deterministic, zero-cost safety against Go's GC, which optimizes simplicity and onboarding but adds runtime overhead. Red flag: calling one strictly superior.

Go & Rust2 min read

Profiling Rust with Linux perf

perf samples CPU stacks thousands of times per second to map where your Rust binary spends time without code changes. Use it on Linux to find hot functions in a slow release build. Omitting debug symbols or frame pointers gives mangled names and broken stacks.

Go & Rust2 min read

Structs: Go's Plain Memory vs Rust's Ownership

Structs bundle named fields into a custom type. Use them when tuples or maps collapse under many values. The footgun is assuming the same syntax means the same rules: Go zero-values fields silently, while Rust demands explicit initialization unless you derive…

Go & Rust2 min read

Primitive Scalars: Go vs Rust

Go's int grows with the architecture; Rust fixes sizes like i32 at compile time. Use Go's int for loops and Rust's i32 for counters, but both require explicit casts to mix. Assuming Go's int is 64-bit breaks 32-bit builds, and Rust's as truncates silently.

Get Rust bites daily.

Five a day, five minutes, offline. With quizzes so it sticks.

Open testing — you’ll join as an early tester.