Skip to content

pahlavaubivca/rust_hello_world

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LEARN DOCS

Task

  1. implement tree
  2. linked list
  3. recursion
  4. async

Ownership

For simple data which stored in stack rust make copy automatic because size is know on compile time

let s1 = 4
let s2 = s1

s1 and s2 stored in different stack, no need store that value in heap

Reference

let asd = 4;
let qwe = &asd;// qwe it is reference to asd, qwe not own the value of asd

Mutable reference

let mut asd = 4;
let qwe = &mut asd;

Mutable reference restriction: if you have a mutable reference to a value, you can have no other references to that value. This code that attempts to create two mutable references to variable will fail.

 let mut s = String::from("hello");

    {
        let r1 = &mut s;
    } // r1 goes out of scope here, so we can make a new reference with no problems.

    let r2 = &mut s;

also combining mutable and immutable reference cause error

Summary about rules of references

  1. at any given time, you can have either one mutable reference or any number of immutable references.
  2. references must always be valid.

Section what is done

  1. data types - in general simple datatypes which stores in stack (i16,i32,str, etc...) and complext which most of the time stores in heap
  2. ownership - by default all data have owner - variable, on = clause we change the owner with futher consequences
  3. smart pointers
  • Box - single owner, allow immutable or mutable borrows(checked at compile time)
  • Rc - multiple owner to the same data, immutable, at compile time
  • RefCell - single owner, allow mutate immutable data, at runtime time

TODO

  1. modules, package and crates
  2. common collections
  3. error handling
  4. io
  5. closures
  6. cargo
  7. concurrency
  8. oop
  9. patterns and matching
  10. multithread

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages