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

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.

主站蜘蛛池模板: 黄陵县| 克山县| 英德市| 贡山| 上栗县| 德格县| 疏附县| 长海县| 长子县| 旺苍县| 西和县| 饶阳县| 阿荣旗| 肥西县| 成都市| 大荔县| 岗巴县| 纳雍县| 江陵县| 綦江县| 广水市| 于都县| 郧西县| 华亭县| 德保县| 康马县| 光山县| 南通市| 夏津县| 临西县| 丽江市| 万盛区| 龙南县| 乌恰县| 广丰县| 广平县| 西和县| 石嘴山市| 正镶白旗| 荃湾区| 岳阳市|