Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dvvcz/constime
Zig's comptime for Rust. Allows you to incorporate side effects into your `const` code.
https://github.com/dvvcz/constime
compile-time comptime macro metaprogramming proc-macro rust
Last synced: 6 days ago
JSON representation
Zig's comptime for Rust. Allows you to incorporate side effects into your `const` code.
- Host: GitHub
- URL: https://github.com/dvvcz/constime
- Owner: DvvCz
- License: mit
- Created: 2023-01-06T04:42:41.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-22T01:06:58.000Z (7 months ago)
- Last Synced: 2024-10-07T23:07:42.187Z (about 1 month ago)
- Topics: compile-time, comptime, macro, metaprogramming, proc-macro, rust
- Language: Rust
- Homepage: https://docs.rs/constime
- Size: 9.77 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
constime
Zig'scomptime
for Rust, with zero dependencies.## Usage
```bash
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
```rust
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()
}
);
}
```