Introduction 介绍
I am Shafin Murani is a software development student and I am documenting every single day of my progress in learning rust. This is the first article of the series.
Shafin Muranishi 是一名软件开发专业的学生,这是他在30天内记录学习Rust的过程。这是该系列的第一篇文章。
If you don't know anything about rust here is what I would interpret it as
如果你对Rust一无所知,我会把它解释为:
“Rust is a systems programming language that prioritizes performance, memory safety, and zero-cost abstractions.”
Rust是一种系统编程语言,优先考虑性能,内存安全和零成本抽象。
Hello World
I have researched about Rust in the past and I have a pretty good understanding of basic programming concepts from Java, C, C++ and Python.
我过去研究过Rust,对Java、C、C++和Python的基本编程概念有很好的理解。
Today I wrote my first hello world
program in rust, here is the code :
今天我用Rust写了我的第一个 hello world
程序,下面是代码:
fn main(){
println!("Hello World");
}
What is going on here?
这是怎么回事?
The fn
keyword is used to declare a function in rust.
关键字 fn
用于在Rust中声明函数。
The main
function is a special function, it is the piece code that runs automatically in every executable program not just Rust but many other languages do the same.main
函数是一个特殊的函数,它是在每个可执行程序中自动运行的代码片段,不仅仅是Rust,许多其他语言也是如此。
The first line declares a main function with no return type
and no arguments
第一行用 no return type
和 no arguments
声明一个main函数
The function body is wrapped in {}
函数体被包装在 {}
中
Inside the main function :
在main函数中:
println!("Hello World");
This line of code prints text to the screen. Now let’s just divide and understand what it does.
这行代码将文本打印到屏幕上。现在我们来分解一下,看看它是干什么的
println!
calls a rust macro to output the passed argument to STDOUT
.println!
调用一个rust宏来输出传递给 STDOUT
的参数。
"Hello World"
is the argument. "Hello World"
是一个参数。
;
specifies the end of a statement.;
指定语句的结尾。
Side note : Rust macros are like personalized shortcuts that help you write code more efficiently by automating repetitive tasks based on your rules.
旁注:Rust宏就像个性化的快捷方式,可以根据规则自动执行重复性任务,从而帮助您更有效地编写代码。
Compiling and running 编译和运行
$ rustc main.rs
$ ls
main.exe main.pdb main.rs
$ .\main.exe
Hello World