Conditional compilation in Rust 0.10?

2020-04-14 08:08发布

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条回答
Melony?
2楼-- · 2020-04-14 08:56

No, there is nothing you can do about this.

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

查看更多
登录 后发表回答