Rust 0.10 中的条件编译? [英] Conditional compilation in Rust 0.10?

查看:37
本文介绍了Rust 0.10 中的条件编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 0.10,最近设置了一个 nightly 版本来与 Box 和朋友们一起试验.

I have been using 0.10 and recently setup a build of nightly to experiment with Box and friends.

现在我有使用 ~str 的 0.10 代码和使用 String 的 pre0.11 代码,因为 to_owned 已过时.我以为我可以这样做:

Now I have code for 0.10 using ~str and code for pre0.11 using String because of to_owned being obsolete. I thought I could do this:

#[cfg(rust_version = "0.10")]
fn my_old_func() -> Option<~str> {
}

#[cfg(not(rust_version = "0.10")]
fn my_old_func() -> Option<String> {
}

并在编译时通过--cfg rust_version:0.11.但是编译器仍然被现在删除的 ~ 操作符阻塞.有没有办法使用条件编译或其他机制让代码在 0.10 和尚未发布的 0.11 下都能运行?

And pass --cfg rust_version:0.11 during compilation. But the compiler still chokes on the now removed ~ operator. Is there a way to have code that works under both 0.10 and the as yet unreleased 0.11 using conditional compilation or some other mechanism?

我想我可以重新使用 cpp 和 #ifdef ,但这似乎已经脱离了 Rust 的思维方式.

I guess I could fall back to using cpp and #ifdef but that seems like stepping out of the Rust mindset.

推荐答案

不,您对此无能为力.

我们的典型建议是不要使用 0.10,而是坚持使用 nightlies.

Our typical recommendation is not to use 0.10 but to stick with nightlies.

这篇关于Rust 0.10 中的条件编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆