Cloning - Rust

#![allow(unused)]
fn main() {
#[derive(Clone, Copy)] // <-- just add this "procedural macro"
pub struct Data {
    value: u32,
}
}

Copy

#![allow(unused)]
fn main() {
#[derive(Clone, Copy)]
pub struct Data {
    value: u32,
}

let data_0 = Data { value: 123 };
let mut data_1 = data_0; // bitwise

data_1.value = 456;

println!("data_0: {}", data_0.value);
println!("data_1: {}", data_1.value);
}

Clone

#![allow(unused)]
fn main() {
#[derive(Clone, Debug)]
pub struct DataOnHeap {
    num: u32,
    value: String,
}

let data_0 = DataOnHeap {
    num: 123,
    value: "hello".into()
};
let mut data_1 = data_0.clone();

data_1.value.make_ascii_uppercase();

println!("data_0: {data_0:#?}");
println!("data_1: {data_1:#?}");
}