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

Playing with features

By default, you can't use the image module with sdl2, we need to activate it. To do so, we need to update our Cargo.toml file by adding a new section as follows:

    [features]
    default = ["sdl2/image"]

default means that by default, the following features ("sdl2/image") will be enabled. Now, let's explain what "sdl2/image" means; sdl2 refers to the crate where we want to enable a feature and image is the feature we want to enable.

Of course, if you want to enable a feature on the current project, you don't need the sdl2/ part. Consider the following example:

    [features]
    network = []
    default = ["network"]

As I am sure you understood, it's absolutely possible to chain features activation and even to activate multiple features at once! If you want to enable features depending on a version number, for example:

    [features]
    network_v1 = []
    network_v2 = ["network_v1"]
    network_v3 = ["network_v2"]
    v1 = ["network_v1"]
    v2 = ["v1", "network_v2"]
    v3 = ["v2", "network_v3"]

So if you enable the v3 feature, all the others will be activated as well! It can be incredibly useful when you need to handle multiple versions at once.

Now let's go back to our images.

主站蜘蛛池模板: 泾源县| 大石桥市| 泗水县| 广灵县| 寿宁县| 蓬莱市| 苏尼特左旗| 文化| 武安市| 兴城市| 通榆县| 全椒县| 虹口区| 抚顺县| 阜平县| 铜川市| 嫩江县| 大竹县| 沁水县| 贞丰县| 双牌县| 丰台区| 青岛市| 子洲县| 喀什市| 施秉县| 于田县| 丹寨县| 贵溪市| 张家港市| 定日县| 泌阳县| 宁国市| 金寨县| 开平市| 浙江省| 灵丘县| 定襄县| 团风县| 钟祥市| 合作市|