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
---
blog.sh | 80 +--------------------------
content/post/no problemo.md | 4 +-
content/post/rust basic.md | 52 ++++++++++++++++++
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 ++++++++++++++++++++
12 files changed, 299 insertions(+), 84 deletions(-)
mode change 100755 => 120000 blog.sh
create mode 100644 content/post/rust basic.md
create mode 100644 public/post/rust-basic/index.html
create mode 100644 public/tags/rust/index.html
diff --git a/blog.sh b/blog.sh
deleted file mode 100755
index 573506d..0000000
--- a/blog.sh
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/usr/bin/env sh
-
-######################################################################
-# @author : garhve (dev@garhve.com)
-# @file : blog
-# @created : Friday Dec 09, 2022 16:09:42 CST
-#
-# @description : simplify blog publishing, it only can use in blog dir
-######################################################################
-
-# usage: prog funct
-
-push() {
- read -r -p "Do you want to push?[y/n] " ans
- if [ "$ans" == 'y' ]; then
- zola build
- git add .
- if [ ! -z "$(git status | grep 'Changes to be committed')" ]; then
- read -r -p "commit message: " msg
- git commit -m "$msg"
- git push origin main
- fi
- echo -e "push done"
- fi
-}
-
-edit() {
- path="content/post"
-
- # --- get editing file
- choice=1
- declare -a arr
- for file in $path/*; do
- [[ "$file" == *"_index.md" ]] && continue
- echo -ne "($choice)\x1b[0;32m${file##*/}\x1b[0m " # n get rid of trailing new line, e strip backslash
- arr[$choice]="$file"
- choice=$((choice+1))
- done
- echo ""
- read -r -p "please choose file by number you want to edit from above: " num
- [[ "$num" == "q" ]] && exit 0
- vim "${arr[$num]}"
- # --- end
- echo -e "edit done\n"
-
- push
- echo -e "\nall done"
-}
-
-new() {
- read -r -p "blog name: " name
- path="content/post/$name"
-
- vim "$path".md
- [ "$?" -eq 0 ] && echo "creation done"
- [ "$?" -ne 0 ] && echo "creation fail, please check error" && exit 1
-
- read -r -p "do you want to edit now?[y/n] " ans
- [ "${ans,,}" == 'y' ] && vim "$path/$name.md" && echo "edit done"
-
- push
-
- echo -e "\nall done"
-}
-
-list() {
- echo -e "\x1b[1;34mList content:\x1b[0m"
- tree ./content/post
-}
-
-
-funct="new/edit/push/ls"
-
-[ $# -lt 1 ] && echo "usage: $(basename $0) $funct"
-
-[ $1 == "new" ] && new
-[ $1 == "edit" ] && edit
-[ $1 == "push" ] && push
-[ $1 == "ls" ] && list
diff --git a/blog.sh b/blog.sh
new file mode 120000
index 0000000..a0f6ce1
--- /dev/null
+++ b/blog.sh
@@ -0,0 +1 @@
+/home/pico/codes/bash/blog-zola.sh
\ No newline at end of file
diff --git a/content/post/no problemo.md b/content/post/no problemo.md
index 5cd9b8c..0728fa0 100644
--- a/content/post/no problemo.md
+++ b/content/post/no problemo.md
@@ -12,7 +12,7 @@ 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](https://en.wikipedia.org/wiki/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.

-It double
+The anime is just about
diff --git a/content/post/rust basic.md b/content/post/rust basic.md
new file mode 100644
index 0000000..8e765b9
--- /dev/null
+++ b/content/post/rust basic.md
@@ -0,0 +1,52 @@
++++
+title = "rust basic -- types and ownership"
+date = 2023-01-12
+[taxonomies]
+categories = ["code"]
+tags = ["rust"]
+[extra]
+math = false
++++
+
+## 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 type | rust | c |
+| ------------- |------------- | ------- |
+| struct | same | same |
+| enum | enum element can be seen as key that could take value | represent numberic value, default starting from 0 |
+| array | vector | array |
+| string | a wraper of vector | pointer of char * |
+| tuple | exist | no 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:
+```rust
+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/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 @@
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.
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 type
rust
c
+
struct
same
same
+
enum
enum element can be seen as key that could take value
represent numberic value, default starting from 0
+
array
vector
array
+
string
a wraper of vector
pointer of char *
+
tuple
exist
no 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.