Expand description
§daywalker - Conditional Nightly Code Inclusion
This crate enables the sharing of code between nightly and stable Rust by
providing conditional inclusion syntax. It is small and lightweight. It works
on a simple principle: use ++[...] to include code only on nightly with the
nightly feature enabled, and --[...] to include code only on stable
without the feature. That’s it!
When the nightly features you’re using are stabilized, you can remove the conditional prefixes (called “bitemarks”) and remove the use of this crate.
§Example
This is the canonical example of the const trait syntax, adapted to use this crate. At the time of this writing, the const trait syntax is only available on nightly. This feature requires a syntax change, which makes it difficult to share code between nightly and stable. Using this crate, however, we can write the same codebase for both nightly and stable by using the conditional inclusion syntax.
#![cfg_attr(feature = "nightly", feature(const_trait_impl))]
daywalker::roam! {
    pub ++[const] trait Default {
        fn default() -> Self;
    }
    impl ++[const] Default for () {
        fn default() -> Self {}
    }
    pub struct Thing<T>(pub T);
    impl<T: ++[[const]] Default> ++[const] Default for Thing<T> {
        fn default() -> Self {
            Self(T::default())
        }
    }
    pub ++[const] fn default<T: ++[[const]] Default>() -> T {
        T::default()
    }
    #[allow(unused_braces)]
    pub fn compile_time_default<T: ++[const] Default>() -> T {
        ++[const] { T::default() }
    }
}Macros§
- roam
- Emits conditionally included code based on nightly feature availability.