官术网_书友最值得收藏!

Setting up your Rust project

The Rust package manager, cargo, allows us to create a new project very easily with just one command, cargo new. Let's run it as follow:

 cargo new tetris --bin

You should have a new folder tetris containing the following:

     tetris/
     |
     |- Cargo.toml
     |- src/
         |
         |- main.rs

Note that if you ran cargo new without the --bin flag, then you will have a lib.rs file instead of main.rs.

Now write this into your Cargo.toml file:

    [package]
    name = "tetris"
    version = "0.0.1"

    [dependencies]
    sdl2 = "0.30.0"

Here, we declare that our project's name is tetris, its version is 0.0.1 (it isn't really important at the moment), and that it has a dependency on the sdl2 crate.

For the versioning, Cargo follows SemVer (Semantic Versioning). It works as follows:

[major].[minor].[path]

So here's exactly what every part means:

  • Update the [major] number version when you make incompatible API changes
  • Update the [minor] number version when adding functionalities that don't break backward compatibility
  • Update the [patch] number version when you make bug fixes that don't break backward compatibility

It's not vital to know this, but it's always nice to be aware of it in case you intend to write crates in the future.

主站蜘蛛池模板: 迁安市| 教育| 上思县| 东兰县| 南昌县| 油尖旺区| 和平区| 阿拉善盟| 兰溪市| 马山县| 枝江市| 临泉县| 定南县| 石河子市| 大关县| 瑞丽市| 达州市| 安阳市| 淮安市| 久治县| 砀山县| 前郭尔| 全州县| 平罗县| 黔江区| 五大连池市| 东海县| 彝良县| 宝坻区| 济阳县| 九台市| 鹤山市| 武胜县| 偃师市| 阳信县| 扶沟县| 德兴市| 永丰县| 公主岭市| 桓台县| 长海县|