Conditionally Include Function based on Rust version

Hello all,

I'm attempting to contribute to someones crate by adding an additional function to their code.

The issue is that within this new function is code that was introduced in Rust 1.53.0 but the current crate compatibility is all the way back to 1.31.0.

Since this new function isn't an integral part of the crates inner workings is there any way to conditionally compile this new function, without introducing a new feature, when compiling with Rust 1.53.0+ ?
something like [cfg(only since 1.53.0)]

Thanks in advance for any help :slight_smile:

You can use autocfg for this.

Awesome thanks!

Even simpler, rustversion.

This one definitely makes the code very readable by intent.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.