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

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.

主站蜘蛛池模板: 河间市| 仙桃市| 游戏| 孙吴县| 林西县| 弥勒县| 舞阳县| 图们市| 尚义县| 阿鲁科尔沁旗| 龙岩市| 汤阴县| 阿鲁科尔沁旗| 万山特区| 天镇县| 辰溪县| 玛多县| 宿松县| 佛冈县| 舟曲县| 文水县| 蕲春县| 开远市| 罗城| 虞城县| 白沙| 高雄县| 黑山县| 闵行区| 恩施市| 长丰县| 景宁| 台东市| 泸溪县| 永新县| 定远县| 高碑店市| 高尔夫| 万源市| 寿宁县| 保亭|