
Copy Versus Clone in Rust and Which Types Are Copy
Copy is an implicit bitwise duplicate and Clone is an explicit call that can do real work. Know which of your types should have which, and what each costs.
Everything you need to level up your coding skills.

Copy is an implicit bitwise duplicate and Clone is an explicit call that can do real work. Know which of your types should have which, and what each costs.

Static dispatch resolves the call at compile time and dynamic dispatch looks it up in a vtable at run time. See the layout, the cost and when it matters.

embedded-hal defines traits for pins, buses and delays so one sensor driver runs on any chip. Write a driver generic over I2C and see how to test it with a mock.

Generic Rust code is compiled once per concrete type, which is why it is as fast as hand written code and why binaries grow. See what that looks like.

E0119 means two impl blocks could apply to the same type. See the common triggers, such as blanket impls and derive plus manual impl, and how to resolve them.

E0117 means you tried to implement a foreign trait for a foreign type. See the exact message, three causes and the newtype or local trait fix.

The orphan rule says you can implement a trait only if the trait or the type is yours. See why it exists, the usual errors and the standard workarounds.

A blanket implementation implements a trait for every type that meets a bound. See how ToString and Into work, the coherence rules that limit you and a safe pattern.

Put the business rules in the middle, describe what they need as traits (ports) and plug in databases and HTTP as adapters. A complete small example with a test double.

A supertrait says a trait requires another one. See the syntax, how methods are inherited, trait objects with supertraits and upcasting.

Box<dyn Trait> costs one allocation and one indirect call per use. Learn what that costs, when it is worth it and the cheaper alternatives.

Dyn compatibility is the set of rules a trait must meet to be used as dyn Trait. Learn each rule, the error it produces and how to keep a trait usable.
We send one email when a new post is published. No spam.