devela/code/util/
deprecate.rs

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
// devela::code::util::deprecate

/// Configures a feature as deprecated, warning if it is enabled.
///
/// You can only call this macro once per deprecated feature.
///
/// # Examples
/// ```
/// # use devela::deprecate_feature;
/// deprecate_feature![old: "old-feature-1"];
/// deprecate_feature![old: "old-feature-2", since: "2.0.0"];
/// deprecate_feature![old: "old-feature-3", new: "new_feature_3"];
/// deprecate_feature![old: "old-feature-4", new: "new_feature_4", since: "4.0.0"];
/// ```
#[macro_export]
#[cfg_attr(cargo_primary_package, doc(hidden))]
macro_rules! deprecate_feature {
    (     old:   $old_feature:literal
      $(, new:   $new_feature:literal )?
      $(, since:       $since:literal )?
    ) => {
        $crate::paste! {
            // old, !new, !since
            #[$crate::compile_attr(
                all( none($($new_feature)?), none($($since)?) ),
                deprecated(note = "\nWARNING. `" $old_feature
                "` feature deprecated." )
            )]

            // old, !new, since
            #[$crate::compile_attr(
                all( none($($new_feature)?), some($($since)?) ),
                deprecated( $(since = $since,)? note = "\nWARNING. `" $old_feature
                "` feature deprecated since version " $($since)? "." )
            )]

            // old, new, !since
            #[$crate::compile_attr(
                all( some($($new_feature)?), none($($since)?) ),
                deprecated(note = "\nWARNING. `" $old_feature
                "` feature deprecated, use `" $($new_feature)? "` instead." )
            )]

            // old, new, since
            #[$crate::compile_attr(
                all( some($($new_feature)?), some($($since)?) ),
                deprecated( $(since = $since,)? note = "\nWARNING. `" $old_feature
                "` feature deprecated since version " $($since)?
                ", use `" $($new_feature)? "` instead." )
            )]

            #[cfg(feature = $old_feature)]
            const fn [<deprecate_feature_ $old_feature:snake>]() {}

            #[cfg(feature = $old_feature)]
            #[allow(dead_code)]
            const [<DEPRECATED_ $old_feature:snake:upper>]: ()
                = [<deprecate_feature_ $old_feature:snake>]();
        }
    };
}
#[doc(inline)]
pub use deprecate_feature;