简体   繁体   English

Rust 选择性 model 库

[英]Rust selective model lib

how can i have crate that depend on with feature use another version of same crate like below我怎样才能拥有依赖于功能的板条箱使用另一个版本的相同板条箱,如下所示

[features]
serde_1 = ["dep_serde_1"]
serde_1_0_133 = ["dep_serde_1_0_133"]

[dependencies]
dep_serde_1 = { package = "serde", version = "1.0.0", optional = true}
dep_serde_1_0_133 = { package = "serde", version = "1.0.133", optional = true}

my problem is compiler force me to use我的问题是编译器强迫我使用

use dep_serde_1::*;

except like this除了这样

use serde::*;

i just enable one of them at time and in code with cfg(feature = serde_1) i'll chose what code must compile我只是在时间和cfg(feature = serde_1)的代码中启用其中一个,我将选择必须编译的代码

sorry about my poor English对不起我糟糕的英语

[Edit] [编辑]

main idea drive form this problem, for example if my model use actix-0.10 and another crate that use my lib use actix-0.12 it generate compiler error主要思想驱动形成这个问题,例如,如果我的 model 使用 actix-0.10 而另一个使用我的 lib 的箱子使用 actix-0.12 它会生成编译器错误

I'm not quite sure I understand what you want.我不太确定我明白你想要什么。 If you want the name of the crate to be serde in your use statements, you can rename them back:如果您希望 crate 的名称在您的 use 语句中为serde ,您可以将它们重命名:

#[cfg(feature = "dep_serde_1")]
extern crate dep_serde_1 as serde;
#[cfg(feature = "dep_serde_1_0_133")]
extern crate dep_serde_1_0_133 as serde;

// Now you can
use serde::*;

Note, by the way, that mutually exclusive features are not a good idea .请注意,顺便说一下,互斥功能不是一个好主意 If you can, it's better to make one the default and the other to override it.如果可以的话,最好将一个设为默认值,另一个将其覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM