Conditional compilation in Rust 0.10?

a 夏天 提交于 2019-12-31 03:14:12

问题


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

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> {
}

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?

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


回答1:


No, there is nothing you can do about this.

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



来源:https://stackoverflow.com/questions/24297154/conditional-compilation-in-rust-0-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!