Prototype in Rust
Prototype is a creational design pattern that allows cloning objects, even complex ones, without coupling to their specific classes.
All prototype classes should have a common interface that makes it possible to copy objects even if their concrete classes are unknown. Prototype objects can produce full copies since objects of the same class can access each other’s private fields.
Built-in Clone trait
Rust has a built-in
std::clone::Clone trait with many implementations for various types (via
#[derive(Clone)]). Thus, the Prototype pattern is ready to use out of the box.