有没有办法在
#[serde(with = "path_handling")]
上添加基于平台的条件?
所以,基本上我只想在 Inix 中使用这个自定义 Serde 方法,在 Windows 上我想使用默认方式。
pub struct Res {
pub last: bool,
#[serde(with = "path_handling")] // ignore this line on windows as path_handling module contains unix specific logic
pub path: PathBuf,
}
cfg_attr
和 target_family
。
pub struct Res {
pub last: bool,
#[cfg_attr(target_family = "unix", serde(with = "path_handling"))]
pub path: PathBuf,
}