4个版本
| 0.2.2 | 2023年1月6日 | 
|---|---|
| 0.2.1 | 2023年1月6日 | 
| 0.2.0 | 2023年1月6日 | 
| 0.1.0 | 2023年1月6日 | 
#778 在 过程宏
5KB
69 行
Constime
这是一个小巧的替代品,用于https://github.com/nhynes/comptime-rs,无依赖,少于80行代码。
用法
cargo add constime
在comptime!中的依赖项可以存储在[dependencies]或[build-dependencies]中,并必须使用extern crate显式导入。
您还需要一个build.rs文件,以便强制[build-dependencies]编译。
示例
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()
		}
	);
}