mirror of https://github.com/sunface/rust-course
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
567 B
567 B
条件编译、条件依赖
通过featre来实现不同的derive
比如有一个类型,我们希望在不同包引用它的时候,派生引用不同的特征,可以这么做:
在Cargo.toml
中定义新的feature
:
[features]
sqlx = []
在类型定义处:
#[cfg_attr(feature = "sqlx", derive(sqlx::Type)]
#[derive(Debug, PartialEq, Deserialize, Serialize, strum_macros::EnumString)]
pub enum Role {Owner,Admin,User,}
在希望派生sqlx
的包:
your_shared_crate = { version = "0.0.1", features = ["sqlx"] }