502 views|1 replies

501

Posts

4

Resources
The OP
 

Rust in Action - Chapter 1: Reading Rust Installation and First Program Experience [Copy link]

  • Rust in Action - Chapter 1: Reading Rust Installation and First Program Experience
    1. Book Overview

Cover

Read the contents of a book directly from the table of contents

    1. Chapter 1 Read Rust Installation

The first chapter introduces the language features of Rust, taking the helloworld program as an example to introduce the language features of Rust.

Overview This chapter provides some initial experience.

I will install rust later to experience it in practice.

https://www.rust-lang.org/zh-CN/

Reference: https://www.rust-lang.org/zh-CN/learn/get-started

Direct command line installation under WSL

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Download the installation package directly under Windows

Open it directly after downloading

Press Enter to install by default

After the installation is complete, press Enter to complete the installation.

    1. First program

1. Enter the working directory cd %TMP%

2. Create a project cargo new helloworld

Print as follows

Created binary (application) `helloworld` package

  1. Enter the project directory cd helloworld
  2. Run the program cargo run

Print as follows

Compiling helloworld v0.1.0 (C:\Users\qinyunti\AppData\Local\Temp\helloworld)

Finished dev [unoptimized + debuginfo] target(s) in 1.08s

Running `target\debug\helloworld.exe`

Hello, world!

The whole process does not require writing a single line of code, and it can be said to be the fastest language to implement the helloworld program.

The ls command shows the following files

Cargo.lock Cargo.toml src target

tree /F View all files

C:\Users\qinyunti\AppData\Local\Temp\helloworld>tree /F

Folder PATH list for volume Windows-SSD

The volume serial number is 4AD2-DD24

C:.

│ .gitignore

│ Cargo.lock

│ Cargo.toml

├─src

│ main.rs

└─target

│ .rustc_info.json

│ CACHEDIR.TAG

└─debug

│ .cargo-lock

│ helloworld.d

│ helloworld.exe

│ helloworld.pdb

├─.fingerprint

│ └─helloworld-1a74b84bc6952173

│ bin-helloworld

│ bin-helloworld.json

│ dep-bin-helloworld

│ invoked.timestamp

├─build

├─deps

│ helloworld.d

│ helloworld.exe

│ helloworld.pdb

├─examples

└─incremental

└─helloworld-5zjffswzj0mv

│ s-guwobqpkw8-12adx41.lock

└─s-guwobqpkw8-12adx41-5w89ateoo09mo6pmr2xvlvj7z

163lw06jy9imt8ev.o

1wzoyque5cqlq6x0.o

2tif3lfmc7za466e.o

3hw4j8v765r39d13.o

3yaezxcbekx0rcwe.o

44p2yw96dxtbmzx7.o

dep-graph.bin

query-cache.bin

work-products.bin

The source code is src/main.rs

I use vscode to open the folder and edit the source code. The source code is as follows

There is only one main function, fn represents function, the entry is the main function, no parameters, println! ("Hello, world!") prints

Use the terminal directly in vscode and run

    1. Summarize

The Rust development environment is very simple to install, and running your first program is also very simple.

Download the code from the following address

https://box.lenovo.com/l/EnyvEo

This post is from Programming Basics

Latest reply

I thought it was a book about boxing when I saw the cover. Is Rust programming language easy to learn? Please share more below.   Details Published on 2024-4-7 07:29
 

6555

Posts

0

Resources
2
 

I thought it was a book about boxing when I saw the cover.

Is Rust programming language easy to learn? Please share more below.

This post is from Programming Basics
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list