The clone()
method is used to create a copy of a value. The value cloned could be any value type such as character, string, number, boolean, etc.
value.clone()
value
: This is the value we want to clone.
The value returned is a copy of the specified value we want to clone.
fn main(){// create some valueslet char1 = 'E';let string1 = "Welcome to Edpresso";let no1 = 200;let bool1 = true;// create cloneslet clone1 = char1.clone();let clone2 = string1.clone();let clone3 = no1.clone();let clone4 = bool1.clone();// print clone valuesprintln!("{}", clone1);println!("{}", clone2);println!("{}", clone3);println!("{}", clone4);}
In the code above:
clone()
.