@@ -75,13 +75,12 @@ is documented in [rust-lang-nursery/error-chain#101].
75
75
76
76
## ` #[cfg(accessible($path))] `
77
77
78
- Consider for a moment that we would like to use the ` Iterator::flatten `
79
- method of the standard library if it exists, but otherwise fall back to
80
- ` Itertools::flatten ` . We can do that with the following snippet:
78
+ Consider for a moment that we would like to use the ` Iterator::flatten ` method
79
+ of the standard library if it exists (because it has become soon in a certain
80
+ Rust version), but otherwise fall back to ` Itertools::flatten ` .
81
+ We can do that with the following snippet:
81
82
82
83
``` rust
83
- #![cfg_attr(feature = " unstable" , feature(iterator_flatten))]
84
-
85
84
#[cfg(accessible(:: std:: iter:: Flatten ))]
86
85
fn make_iter (limit : u8 ) -> impl Iterator <Item = u8 > {
87
86
(0 .. limit ). map (move | x | (x .. limit )). flatten ()
@@ -100,33 +99,33 @@ fn main() {
100
99
101
100
What this snippet does is the following:
102
101
103
- 1 . If the cargo feature ` unstable ` is enabled and assuming the compiler is
104
- capable of feature gates, but not otherwise, the feature ` iterator_flatten `
105
- will be enabled.
106
-
107
- 2 . If the path ` ::std::iter::Flatten ` exists, the compiler will compile
102
+ 1 . If the path ` ::std::iter::Flatten ` exists, the compiler will compile
108
103
the first version of ` make_iter ` . If the path does not exist,
109
104
the compiler will instead compile the second version of ` make_iter ` .
110
105
111
- The result of 1. and 2. is that your crate can opt into using
112
- ` Iterator::flatten ` when ` feature = "unstable" ` is enabled,
113
- but use ` Itertools::flatten ` on stable compilers meanwhile.
114
- Once the standard library has stabilized ` iter::Flatten ` ,
115
- future stable compilers will start using the first version of the function.
116
- As a crate author, you don't have to publish any new versions of your crate for
117
- the compiler to switch to the libstd version when it is available in the future.
106
+ The result of 1. is that your crate will use ` Iterator::flatten ` on newer
107
+ versions of Rust and ` Itertools::flatten ` on older compilers.
108
+ The result of this is that as a crate author, you don't have to publish any
109
+ new versions of your crate for the compiler to switch to the libstd version
110
+ when people use a newer version of Rust.
118
111
119
112
[ `proptest` ] : https://github.com/altsysrq/proptest
120
113
[ adding support ] : https://github.com/AltSysrq/proptest/blob/67945c89e09f8223ae945cc8da029181822ce27e/src/num.rs#L66-L76
121
114
122
- In this case we used the ` feature = "unstable" ` and ` accessible ` flags
123
- to handle a problem that the addition of ` Iterator::flatten ` caused for us
124
- if we had used ` Itertools::flatten ` . We can also use these mechanisms for
125
- strictly additive cases as well. Consider for example the [ ` proptest ` ] crate
126
- [ adding support] for ` RangeInclusive ` :
115
+ Once the standard library has stabilized ` iter::Flatten ` ,
116
+ future stable compilers will start using the first version of the function.
117
+
118
+ In this case we used the ` accessible ` flag to handle a problem that the addition
119
+ of ` Iterator::flatten ` caused for us if we had used ` Itertools::flatten ` .
120
+ We can also use these mechanisms for strictly additive cases as well.
121
+ Consider for example the [ ` proptest ` ] crate [ adding support] for ` RangeInclusive ` :
127
122
128
123
``` rust
129
- #[cfg_attr(feature = " unstable" , feature(inclusive_range))]
124
+ // #[cfg_attr(feature = "unstable", feature(inclusive_range))]
125
+ // ^-- If you include this line; then `cargo build --features unstable`
126
+ // would cause nightly compilers to activate the feature gate.
127
+ // Note that this has some inherent risks similar to those for
128
+ // `#[cfg(nightly)]` (as discussed later in this RFC).
130
129
131
130
macro_rules! numeric_api {
132
131
($ typ : ident ) => {
0 commit comments