fn main() {

    let s1 = String::from("hello");
    let s2 = s1;

    //println!("{}, world!", s1); Error because the varibale s1 is now tranfered to s2. When the
    //memory will be cleared only th register address of s2 will be detelted . 
    //this is not he case in intergers who alsways have the same an defined size. 
    println!("{}, world!", s2);


    // Clone lets you colne the varibale AKA deep copy. 
    let s3 = String::from("hello");
    let s4 = s3.clone();
    println!("s1 = {}, s2 = {}", s3, s4);


    let s = String::from("hello");  // s comes into scope

    takes_ownership(s);             // s's value moves into the function...
                                    // ... and so is no longer valid here

    let x = 5;                      // x comes into  scope
    makes_copy(x);                  // x would move into the function,
                                    // but i32 is Copy, so it's okay to still use x afterwards



    let s5 = String::from("hello");

    let (s6, len) = calculate_length(s5);

    println!("The length of '{}' is {}.", s6, len);

}


fn takes_ownership(some_string: String) { // some_string comes into scope
        println!("{}", some_string);
} // Here, some_string goes out of scope and `drop` is called. The backing
  // memory is freed.

fn makes_copy(some_integer: i32) { // some_integer comes into scope
       println!("{}", some_integer);
} // Here, some_integer goes out of scope. Nothing special happens.

fn calculate_length(s: String) -> (String, usize) {
    let length = s.len(); // len() returns the length of a String
    (s, length)
}
