constime

Crates.ioconstime
lib.rsconstime
version0.2.2
sourcesrc
created_at2023-01-06 07:04:28.512633
updated_at2023-01-06 10:37:00.634892
descriptionZig's comptime for Rust with zero dependencies. Mostly something to play around with until more stuff is const fn.
homepage
repositoryhttps://github.com/DvvCz/Constime
max_upload_size
id752119
size6,805
Oncelock (DvvCz)

documentation

README

Constime

This is a tiny alternative to https://github.com/nhynes/comptime-rs, with no dependencies and <80 LOC.

Usage

cargo add constime

Dependencies in comptime! can be stored in either [dependencies] or [build-dependencies], and must be explicitly imported using extern crate.

You will also need a build.rs file in order to force [build-dependencies] to compile.

Example

fn main() {
	use constime::comptime;

	// Let's use a pure-build time dependency
	println!("Here's a fact about the number 5: {}", comptime! {
		extern crate ureq;
		ureq::get("http://numbersapi.com/5/math").call().unwrap().into_string().unwrap()
	});

	// Standard library works fine too.
	println!(
		"Compiled {} seconds after unix epoch.",
		comptime! {
			std::time::SystemTime::now()
				.duration_since(std::time::UNIX_EPOCH)
				.expect("Time went backwards")
				.as_secs()
		}
	);
}
Commit count: 7

cargo fmt