type
status
date
slug
summary
tags
category
icon
password
About these notes
These Rust notes are just a collection of my learning records. Since I'm a beginner in Rust, these notes are more like quick references or supplements, rather than a comprehensive Rust tutorial. No matter what, I hope you can still find parts that are useful to you.
Why rust?
Rust's advantages include memory safety, high performance, and high productivity. To me, Rust appears to be one of the best implementations of C++. If you don't get into deeper topics and only use prepared libraries, Rust's syntax is simple and clear. Its built-in compiler cautions are also quite informative, which significantly decreases the amount of thinking required on developers.
However, Rust has been criticized for being "too safe." If you want to dig deeper and truly utilize Rust, you'll have to deal with its complex and tedious safety mechanisms. A true dilemma exists: "Why not use the more flexible C++, or Python, which offers quicker speed in development and a more strong ecosystem?"
In my opinion, Rust is a "balanced" choice that addresses some shortcomings of mainstream languages. It is safer than C++ and performs better than Python. However, Rust has obvious drawbacks including an extremely high learning and development cost (which may be more difficult than learning C++). However, Rust is clearly a popular technology right now, and its ecosystem is rapidly expanding. Learning a challenging new language is never a terrible idea.
Environment prep
- Follow the instructions at https://www.rust-lang.org/learn/get-started to install Rust.
- Install VS Code.
- Install the rust-analyzer extension in VS Code.
- Well done! You’re now ready to write your first Rust program.
Use Google or AI tools to help you do these tasks, you will deal with Google and AI all the time when you’re learning something new.
Hello world
- In VS Code, open a new folder.
- Press
Ctrl + `
to open a new terminal, or you can follow the top menu tabs: "Terminal" -> "New Terminal".
- Enter
cargo new helloworld
to create a new project namedhelloworld
. cargo
is like thepip
in Python; it manages packages (libraries) in Rust.
- Go into the
src
folder, and you will find themain.rs
file.
- Enter
cargo run
in the terminal to directly run … oops! An error occurs. - You need to first navigate into the
helloworld
directory because that’s the project’s working directory. - Use
cd helloworld
, or open the folder again in VS Code, and then create a new terminal. - Enter
cargo run
. - Congratulations! You've run your first Rust program!
- Author:Parker Chen
- URL:www.parkerchenca.com/article/108f0ccf-d7f8-8027-8de9-f24c23990c10
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts