Skip to content

Add Chapter 3: Traits & Generics#2

Closed
hartsock wants to merge 2 commits into
ch02-error-handlingfrom
ch03-traits-and-generics
Closed

Add Chapter 3: Traits & Generics#2
hartsock wants to merge 2 commits into
ch02-error-handlingfrom
ch03-traits-and-generics

Conversation

@hartsock

Copy link
Copy Markdown
Member

Summary

  • Maps Python ABCs, Protocols, duck typing to Rust traits
  • Covers: trait definition, generics with bounds, default methods, #[derive], operator overloading (Add, Sub, Display), static vs dynamic dispatch, where clauses
  • 16 passing example tests, 5 exercises with todo!() stubs

Test plan

  • cargo test -p ch03-traits-and-generics — 16/16 pass
  • cargo clippy --workspace -- -D warnings — clean
  • cargo fmt --all -- --check — clean
  • No private repo references (audited)

Depends on #1

🤖 Generated with Claude Code

hartsock and others added 2 commits April 12, 2026 21:45
Maps Python's try/except/None to Rust's Result<T,E>, Option<T>, and the ?
operator. Covers custom error types, Option chaining, iterator collect into
Result, and the LBYL/EAFP/types comparison.

16 passing example tests, 5 exercises with todo!() stubs.

Also fixes ch01 Logger exercise: replaced todo!() in Drop impl with a
comment-only stub to avoid double-panic abort in the test runner.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Maps Python's ABCs/Protocols/duck typing to Rust's trait system. Covers
trait definition and implementation, generic functions with trait bounds,
default methods, derived traits, operator overloading (Add, Sub, Display),
static vs dynamic dispatch, and multiple trait bounds with where clauses.

16 passing example tests, 5 exercises with todo!() stubs covering HasArea
trait, generic largest_area, Display for Temperature, Add for Money, and
dynamic dispatch with Renderable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hartsock hartsock force-pushed the ch02-error-handling branch from 437d641 to 364de6d Compare April 13, 2026 23:55
@hartsock hartsock deleted the branch ch02-error-handling April 13, 2026 23:56
@hartsock hartsock closed this Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant