Tips and tricks to avoid cloning

In Rust, it is often better to avoid cloning if possible to avoid unnecessary allocation. Here is a list of techniques I use most often to do that. All titles are links to Rust playgrounds if you want to play with the examples. Implement the Copy trait For small data types, cloning might actually be the cheapest option. There is a special trait for that named Copy . Whenever possible, you should…