| Crates.io | daywalker |
| lib.rs | daywalker |
| version | 1.0.0 |
| created_at | 2025-09-07 12:50:44.320748+00 |
| updated_at | 2025-09-07 12:50:44.320748+00 |
| description | proc-macro for nightly conditional tokens |
| homepage | https://github.com/npmccallum/daywalker |
| repository | https://github.com/npmccallum/daywalker |
| max_upload_size | |
| id | 1828102 |
| size | 12,108 |
Write nightly-conditional code once. Run on both nightly and stable Rust.
#![cfg_attr(feature = "nightly", feature(const_trait_impl))]
daywalker::roam! {
pub ++[const] trait Name {
fn name(&self) -> &'static str;
}
impl ++[const] Name for () {
fn name(&self) -> &'static str {
++["nightly"] --["stable"]
}
}
}
fn main() {
println!("Hello, {}!", ().name());
}
Perfect for library authors - write once, let users choose between nightly features or stable compatibility.
roam! { ... }.++[...]: Emit code only when nightly feature is enabled--[...]: Emit code only when nightly feature is disabledWrite nightly-optional code that work for everyone! First, expose the choice to your library users:
# Cargo.toml
[package]
name = "cool-lib"
version = "1.0.0"
[dependencies]
daywalker = "1.0"
[features]
nightly = ["daywalker/nightly"]
Then, define and implement conditional code using the nightly syntax with prefix operators:
// src/lib.rs
#![cfg_attr(feature = "nightly", feature(const_trait_impl))]
daywalker::roam! {
pub ++[const] trait Compute {
fn compute(&self) -> u32;
}
impl ++[const] Compute for u32 {
fn compute(&self) -> u32 { *self * 2 }
}
}
If you want to run on stable rust, use the library like normal. First, add the dependency:
# Cargo.toml
[dependencies]
cool-lib = "1.0"
Then use the dependency:
// src/main.rs
use cool_lib::Compute;
let value: u32 = 42u32.compute(); // ✅ Runtime
That's it!
On the other hand, if you want that sweet nightly functionality and are willing
to accept the requirement to compile only on nightly, then just use the
nightly feature:
# Cargo.toml
[dependencies]
cool-lib = { version = "1.0", features = ["nightly"] }
Look, you get nightly features!
// src/main.rs
#![feature(const_trait_impl)]
use cool_lib::Compute;
const VALUE: u32 = 42u32.compute(); // ✅ Compile-time