1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*!
This is a small crate that just export one macro that allow you to have code
conditionally of the rust version.
The [`if_rust_version!`](macro.if_rust_version.html) macro allows you to still
support older version
of rustc while still using conditionally new features of the compiler
# Examples
The release of rust 1.36 stabilized the `MaybeUninit` union as a replacement
for the to be deprecated `mem::uninitialized`. One might want to use
MaybeUninit when the compiler supports it, but not without requiring a recent compiler.
The `if_rust_version!` macro is exactly what one needs:
```rust
# #[macro_use] extern crate if_rust_version;
# fn main() {
# use std::mem;
# use std::ptr;
if_rust_version! { >= 1.36 {
let mut x = std::mem::MaybeUninit::<u32>::uninit();
unsafe { x.as_mut_ptr().write(32); }
let xx = unsafe { x.assume_init() };
} else {
let mut xx : u32 = unsafe { mem::uninitialized() };
unsafe { ptr::write(&mut xx as *mut u32, 32); }
}}
assert_eq!(xx, 32);
# }
```
*/
/*!
# Minimum Rust version
The minimum rust version is rust 1.12, because previous versions were
not expanding `tt` correcrtly in `macro_rules!`
This crate has no dependencies, and is `#![no-std]`.
# Comparison with other crates
There are other crates that check the rust version number:
[version_check](https://crates.io/crates/version_check) and
[rustc_version](https://crates.io/crates/rustc_version).
The main difference is that these crates are meant to to be
used by first writing a `build.rs` script to then add some
feature flag.
*/
include!;