constime

Crates.ioconstime
lib.rsconstime
version
sourcesrc
created_at2023-01-06 07:04:28.512633+00
updated_at2025-01-18 05:23:25.659965+00
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
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Oncelock (DvvCz)

documentation

README

constime

Zig's comptime for Rust, with zero dependencies.

GitHub Actions Workflow Status Crates.io Version GitHub Release

Usage

cargo add constime

Dependencies in comptime! can be stored in either [dependencies] or [build-dependencies].

If you use build dependencies, you will need to explicitly link with extern crate and a build.rs file to force them 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()
		}
	);
}

Note

You should get autocomplete and error feedback when using the macro.

This works with temporary files, which currently aren't automatically cleared.

If you notice your project getting a little large, periodically run cargo clean to remove these.

Commit count: 12

cargo fmt