Coder Social home page Coder Social logo

rust_practice's Introduction

rust_practice

my practice for learning rust

Day01 Notes

Install rust & visual studio code's extensions

Install Rust:

Visual studio code extensions

About rust common commands

  1. rustup
  2. rustc

About rust's package management tool

  1. cargo

Day02 Notes

Ch02_01 Variables

Declare immutable varianle

  • Let x: i32 = 5; or let x = 5; x is i32

Declare mutable varianle

  • Let mut x: i32 = 5; or let mut x = 5; x is i32

Shadowing

Shadowing
fn variables_shadowing() {
    let x = 5;
    let x = x + 1;
    let x = x * 2;
    println!("The value of x is: {}", x);
    // The value of x is: 12
}
Non-Shadowing
fn variables_shadowing() {
    let x = 5;
    let y = x + 1;
    let z = y * 2;
    println!("The value of z is: {}", z);
    // The value of z is: 12
}

shadowing vs mutable

1. The shadowing can change datatype, but mutable can't. 2. The shadowing is alway immutable.

Naming rule for variable

  1. Snake Case: Let _nice_count : i32 = 0;
  2. Pascal Case(For enumerate and structure)

Casting a value to a different type

Let __nice_count_one : i32 = 0;
Let _nice_count_two = __nice_count_one as i32;

Print out variable

println!("Value is: {}", __nice_count_one); println!("Value is: {__nice_count_one}");

rust_practice's People

Contributors

hanksjctsai avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.