changed their order

This commit is contained in:
Tahinli 2023-05-07 03:44:57 +03:00
parent 11cf6d0135
commit 1736280dcd
4 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,8 @@
[package]
name = "move_clone_copy"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View file

@ -0,0 +1,27 @@
fn main()
{
println!("Hello, world!");
//Keeps data in heap
//Information about data are in stack
//Because data can be changed in runtime
//"Move" like shallow copy but invalidates original
let s1 = String::from("Some Data");
let s2 = s1;
//println!("s1 = {}", s1); s1 isn't valid
println!("s2 = {}", s2);
//"Clone" like deep copy
let s3 = String::from("Another Data");
let s4 = s3.clone(); //Data in heap will be copied
println!("s3 = {}", s3);
println!("s4 = {}", s4);
//"Copy" all data are in stack
//Because size is known while compiling
let x = 5;
let y = x;
println!("x = {}", x);
println!("y = {}", y);
}