From d743c344988884c81e247a0ab9c2696912d8a1e3 Mon Sep 17 00:00:00 2001 From: garhve Date: Thu, 12 Jan 2023 19:13:20 +0800 Subject: first half of the first rust note --- public/categories/code/index.html | 9 ++++ public/categories/index.html | 2 +- public/index.html | 28 ++++++++++ public/post/index.html | 28 ++++++++++ public/post/no-problemo/index.html | 4 +- public/post/rust-basic/index.html | 107 +++++++++++++++++++++++++++++++++++++ public/sitemap.xml | 7 +++ public/tags/index.html | 5 ++ public/tags/rust/index.html | 57 ++++++++++++++++++++ 9 files changed, 244 insertions(+), 3 deletions(-) create mode 100644 public/post/rust-basic/index.html create mode 100644 public/tags/rust/index.html (limited to 'public') diff --git a/public/categories/code/index.html b/public/categories/code/index.html index ef76831..5573296 100644 --- a/public/categories/code/index.html +++ b/public/categories/code/index.html @@ -35,6 +35,15 @@

[Category: code]

+

+

+ 2023-01-12 +
+
+ rust basic -- types and ownership +
+

+

2022-09-29 diff --git a/public/categories/index.html b/public/categories/index.html index addaa1a..bb154ac 100644 --- a/public/categories/index.html +++ b/public/categories/index.html @@ -38,7 +38,7 @@
  • /code - (3) + (4)
  • diff --git a/public/index.html b/public/index.html index 44f11a4..51cc3e5 100644 --- a/public/index.html +++ b/public/index.html @@ -35,6 +35,34 @@ +

    2023

    + + +

    +

    + 2023-01-12 +
    + + + +
    + + +  /code + + + + + +  #rust + + +
    +

    + +

    2022

    diff --git a/public/post/index.html b/public/post/index.html index 44f11a4..51cc3e5 100644 --- a/public/post/index.html +++ b/public/post/index.html @@ -35,6 +35,34 @@ +

    2023

    + + +

    +

    + 2023-01-12 +
    + + + +
    + + +  /code + + + + + +  #rust + + +
    +

    + +

    2022

    diff --git a/public/post/no-problemo/index.html b/public/post/no-problemo/index.html index cb80737..3742499 100644 --- a/public/post/no-problemo/index.html +++ b/public/post/no-problemo/index.html @@ -55,9 +55,9 @@

    My feeling to express are fading... Not sure how I know it, just got this sense.

    Recently, I picked up an anime named "The Simpsons" which I watched first episode back in highschool. This first time was not gave me too much impression. -but I fell in love with it right after re-watched first episode! So I downloaded the series up to 17.(33 in total but I'm not in rush) +but I fell in love with it right after re-watched first episode! So I downloaded the half of the whole series. simpson tv list

    -

    It double

    +

    The anime is just about

    diff --git a/public/post/rust-basic/index.html b/public/post/rust-basic/index.html new file mode 100644 index 0000000..262aee3 --- /dev/null +++ b/public/post/rust-basic/index.html @@ -0,0 +1,107 @@ + + + + + + +rust basic -- types and ownership | garhve's gibberish + + + + + + + + + + + + + + +
    +
    + +

    +

    rust basic -- types and ownership
    +

    +

    +

    2023-01-12
    +
    + + + /code + + + + +  #rust + + +
    +

    + +

    +

    Types

    +
    +

    This is a summary of rust basic knowledge I learned from (Rust the Book)[https://doc.rust-lang.org/book/] chapter 1 ~ chapter 13 +I will use C to compare with since I familiar it.

    +
    +

    There are a bunch of built-in types we can work with: scalar types and compound types. +Those scalar types are just alike as C language. +| scalar types | rust | c | +| ------------- |------------- | ------- | +| integer | i(u)8/i16/i32/i64 | (unsigned) char/short/int/long | +| float | f32/f64 | float/double | +| boolean | true/false | True/False (non-zero/zero) | +| character | char | char |

    +

    The compound types are a bit different. rust provides many hands-on types where C type is not the same or needs to define explicitly.

    + + + + + + +
    compound typerustc
    structsamesame
    enumenum element can be seen as key that could take valuerepresent numberic value, default starting from 0
    arrayvectorarray
    stringa wraper of vectorpointer of char *
    tupleexistno such type in C
    +

    Variable declaration in rust is kinda tricky.

    +

    A normal declare syntax would be like let unmutable_variable = 3. This will imply that variable is i32 type +since the value we assign to is a integer and the default type for integer on most OS is i32. +We can explicit type by using type annotation: let unmutable_variable: u8 = 3. This will make variable +unmutable_variable is u8 type and has 3 as its value. We need to assign a value +to variable if we don't annotate type while declaration, otherwise compiler would prompt error.

    +

    Notice that, declaration as above one won't allow us to change value, if we want to be able to change variable's +value at runtime, we need to explicit it, for security reason:

    +
    let mut mutable_variable = 3;
    +println!("first define: {mutable_variable}");
    +mutable_variable = 5;
    +
    +println!("change value to: {mutable_variable}");
    +
    +
    +

    println!() is called macro, which would not cover for now.

    +
    + +

    + + + + +
    +
    + + + + + diff --git a/public/sitemap.xml b/public/sitemap.xml index 02cae4b..89cf628 100644 --- a/public/sitemap.xml +++ b/public/sitemap.xml @@ -58,6 +58,10 @@ https://blog.garhve.com/post/past-is-great/ 2022-11-07 + + https://blog.garhve.com/post/rust-basic/ + 2023-01-12 + https://blog.garhve.com/post/sui-bi-1/ 2022-12-20 @@ -77,4 +81,7 @@ https://blog.garhve.com/tags/linux/ + + https://blog.garhve.com/tags/rust/ + diff --git a/public/tags/index.html b/public/tags/index.html index 64ba538..3aa2945 100644 --- a/public/tags/index.html +++ b/public/tags/index.html @@ -56,6 +56,11 @@ (1)
  • +
  • + #rust + (1) +
  • +
    diff --git a/public/tags/rust/index.html b/public/tags/rust/index.html new file mode 100644 index 0000000..5928831 --- /dev/null +++ b/public/tags/rust/index.html @@ -0,0 +1,57 @@ + + + + + + +rust | garhve's gibberish + + + + + + + + + + + +
    + + +
    + + +
    +
    + +

    [Tag: rust]

    + + +

    +

    + 2023-01-12 +
    + +

    + + + +
    +
    + + + + + -- cgit v1.2.3-70-g09d2