0x00. Develop a complete application using rust

Time:2021-12-2

When I first started learning rust, I didn’t know how to continue after reading the official recommended tutorials such as rust book. I think many people should feel the same as me. Later, I found a tutorial for developing complete applications with rust. Unfortunately, I can’t find that series of tutorials on the author’s blog now, But the code I wrote when I knew little is still there. Now I want to restore that tutorial

First of all, let’s introduce this project. This is arust-sdl2At the same time, most of the syntax features of rust are used to develop a desktop application

Nuggets catalog

0x00. Develop a complete application using rust

catalogue

0x00. Develop a complete application using rust
0x01. Create a window using sdl2
0x02. Processing window closed
0x03. Define events using macros
0x04. View rendering
0x05. View operation
0x06. Rectangle on window
0x07. Processing Wizard
0x08. Add game background

Preparation before start

Before you start coding, you have to match some things, so put them firstSDL2Put it on, inmacOSInstall by executing commands directly on the terminalbrew install sdl2, install a higher version ofRust, preferablynightlyBecause 2018 edition will be used, and there are some other thingsunstablecharacteristic.

My native rust version

rust 1.37.0-nightly (0e4a56b4b 2019-06-13)

Then select a directory to create the project

cargo new rs-arcade

Modify itCargo.tomlFile, add itrust-sdl2Dependency, used here0.29Version, because0.30I haven’t learned the later version yet. After the whole project is completed, migrating to the new version can also be used as a learning goal

[package]
name = "rs-arcade"
version = "0.1.0"
authors = ["LimitLiu <[email protected]>"]
edition = "2018"

[dependencies]
sdl2 = "0.29"

Next, execute directly in the project root directorycargo runStart and install the dependency. Considering that the domestic network is excellent, it is recommended to configure a domestic source
The official warehouse ishttps://crates.io, we are$HOME/.cargoCreate a directoryconfigFile, add these contents

[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

Save it before executingcargo run.

When the implementation is successful, we upload the code to the GIT hosting platform. I use the domestic coding platform for hosting. The reason is still the excellent domestic network. / / although it has become painful now
https://git.dev.tencent.com/limitLiu/rs-arcade.git


Now that you have finished the initial work of the project, display the window first

This work adoptsCC agreement, reprint must indicate the author and the link to this article