#build #time #timestamp #compile #string

macro no-std build_timestamp

Simple proc-macro to generate a build timestamp string as a const

1 unstable release

Uses old Rust 2015

0.1.0 Sep 8, 2018

#39 in #timestamp

Download history 392/week @ 2023-10-20 490/week @ 2023-10-27 338/week @ 2023-11-03 416/week @ 2023-11-10 567/week @ 2023-11-17 509/week @ 2023-11-24 429/week @ 2023-12-01 379/week @ 2023-12-08 372/week @ 2023-12-15 127/week @ 2023-12-22 143/week @ 2023-12-29 296/week @ 2024-01-05 304/week @ 2024-01-12 348/week @ 2024-01-19 458/week @ 2024-01-26 386/week @ 2024-02-02

1,542 downloads per month

MIT/Apache

7KB

Build Timestamp String Generator

build_timestamp is a simple proc-macro for Rust to generate a const string with a build timestamp (in UTC), formatted with strftime syntax.

Note: using this crate makes your build non-deterministic!

Note: using this crate requires nightly Rust

Example

// Rust2018 macro import
use build_timestamp::build_time;

// generates a `const BUILD_TIME: &str`
build_time!("%A %Y-%m-%d / %H:%M:%S");

fn main() {
    println!("This is {}, built on: {}",
        env!("CARGO_PKG_NAME"), BUILD_TIME);
}

Running this example will print something that looks like:

This is my_crate, built on: Saturday 2018-09-08 / 11:35:43

TODO

Features that I'd like this crate to support in the future:

  • proper error handling (currently just uses unwrap() to panic)
  • ability to specify the name for the generated const
  • non-UTC timezones

If you would like to implement any of this, I welcome patches.

Dependencies

~2.5MB
~57K SLoC